0
点赞
收藏
分享

微信扫一扫

Linux的基本指令(3)

扶摇_hyber 2024-10-10 阅读 22

题目:

题解:

struct hashTable {
int key;
int val;
UT_hash_handle hh;
};

int fourSumCount(int* A, int ASize, int* B, int BSize, int* C, int CSize, int* D, int DSize) {
struct hashTable* hashtable = NULL;
for (int i = 0; i < ASize; ++i) {
for (int j = 0; j < BSize; ++j) {
int ikey = A[i] + B[j];
struct hashTable* tmp;
HASH_FIND_INT(hashtable,
if (tmp == NULL) {
struct hashTable* tmp = malloc(sizeof(struct hashTable));
tmp->key = ikey, tmp->val = 1;
HASH_ADD_INT(hashtable, key, tmp);
} else {
tmp->val++;
}
}
}
int ans = 0;
for (int i = 0; i < CSize; ++i) {
for (int j = 0; j < DSize; ++j) {
int ikey = -C[i] - D[j];
struct hashTable* tmp;
HASH_FIND_INT(hashtable,
if (tmp != NULL) {
ans += tmp->val;
}
}
}
return ans;
}
举报

相关推荐

0 条评论