From 2f2e6856dbda03d1580b4301bf62dee04b0f641b Mon Sep 17 00:00:00 2001 From: qiuzidian <115708838+qiuzidian@users.noreply.github.com> Date: Mon, 29 Jan 2024 22:08:52 +0800 Subject: [PATCH] =?UTF-8?q?Update=200454.=E5=9B=9B=E6=95=B0=E7=9B=B8?= =?UTF-8?q?=E5=8A=A0II.md=EF=BC=8C=E8=A7=84=E8=8C=83=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E6=A0=BC=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- problems/0454.四数相加II.md | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/problems/0454.四数相加II.md b/problems/0454.四数相加II.md index 3baeade5..a0bf84da 100644 --- a/problems/0454.四数相加II.md +++ b/problems/0454.四数相加II.md @@ -418,20 +418,19 @@ public int FourSumCount(int[] nums1, int[] nums2, int[] nums3, int[] nums4) { // 哈希表大小 const int HASH_SIZE = 101; -typedef struct node -{ +typedef struct node { int val; int count; struct node *next; -}node, *HashMap; +} node, *HashMap; // 哈希表插入 -void hash_insert(HashMap hashmap[], int val){ +void hash_insert(HashMap hashmap[], int val) { int idx = val < 0 ? (-val) % HASH_SIZE : val % HASH_SIZE, count = 0; node *p = hashmap[idx]; while (p->next != NULL) { p = p->next; - if (p->val == val){ + if (p->val == val) { (p->count)++; return; } @@ -445,10 +444,10 @@ void hash_insert(HashMap hashmap[], int val){ } // 哈希表查找 -int hash_search(HashMap hashmap[], int val){ +int hash_search(HashMap hashmap[], int val) { int idx = val < 0 ? (-val) % HASH_SIZE : val % HASH_SIZE; node *p = hashmap[idx]; - while (p->next != NULL){ + while (p->next != NULL) { p = p->next; if (p->val == val) return p->count; } @@ -458,23 +457,23 @@ int hash_search(HashMap hashmap[], int val){ int fourSumCount(int* nums1, int nums1Size, int* nums2, int nums2Size, int* nums3, int nums3Size, int* nums4, int nums4Size){ // 初始化哈希表 HashMap hashmap[HASH_SIZE]; - for (int i = 0; i < HASH_SIZE; i++){ + for (int i = 0; i < HASH_SIZE; i++) { hashmap[i] = malloc(sizeof(node)); hashmap[i]->next = NULL; } // 统计两个数组元素之和的负值和出现的次数,放到哈希表中 int count = 0, num; - for (int i=0; i