Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
Signed-off-by: begeekmyfriend <[email protected]>
  • Loading branch information
begeekmyfriend committed Jul 25, 2017
1 parent cee8800 commit f61316c
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
3 changes: 2 additions & 1 deletion 001_two_sum/two_sum.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ static int * twosum(int *nums, int numsSize, int target)
hlist_for_each(pos, &ht[hash].head) {
struct plus_elem *elem = hlist_entry(pos, struct plus_elem, node);
if (elem->num == other) {
if (elem->index != i) {
/* Eliminate duplicate */
if (elem->index > i) {
index = elem->index;
break;
}
Expand Down
1 change: 1 addition & 0 deletions 015_three_sum/three_sum.c
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ static int** threeSum(int* nums, int numsSize, int* returnSize) {
hlist_for_each(pos, &ht[hash].head) {
struct plus_elem *elem = hlist_entry(pos, struct plus_elem, node);
if (elem->num == other) {
/* Eliminate duplicate */
if (elem->index > j) {
index = elem->index;
break;
Expand Down
6 changes: 3 additions & 3 deletions 018_four_sum/four_sum.c
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,7 @@ static int** fourSum(int* nums, int numsSize, int target, int* returnSize) {
for (i = 0; i < numsSize - 1; i++) {
for (j = i + 1; j < numsSize; j++) {
int new_target = target - nums[i] - nums[j];
for (k = 0; k < numsSize; k++) {
if (k == i || k == j) continue;
for (k = j + 1; k < numsSize; k++) {
int other = new_target - nums[k];
int hash = other < 0 ? -other % numsSize : other % numsSize;
int index = -1;
Expand All @@ -143,7 +142,8 @@ static int** fourSum(int* nums, int numsSize, int target, int* returnSize) {
hlist_for_each(pos, &ht[hash].head) {
struct element *elem = hlist_entry(pos, struct element, node);
if (elem->num == other) {
if (elem->index != i && elem->index != j && elem->index != k) {
/* Eliminate duplicate */
if (elem->index > k) {
index = elem->index;
break;
}
Expand Down

0 comments on commit f61316c

Please sign in to comment.