Skip to content

Commit 3999b66

Browse files
committed
⚡ [q15] -
1 parent be8fd4f commit 3999b66

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

15/my_solution.js

+16-7
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,25 @@
33
* @return {number[][]}
44
*/
55
const threeSum = (nums) => {
6-
76
let result = [];
7+
nums.sort((a, b) => a - b);
8+
console.log(nums)
9+
810
for (let i = 0; i < nums.length; i++) {
11+
if (undefined !== nums[i - 1] && nums[i - 1] === nums[i]) {
12+
console.log("-------------------> !!!! same as prev")
13+
console.log(nums[i - 1])
14+
console.log(nums[i])
15+
continue;
16+
}
17+
918
let tmpList = [...nums];
10-
// , tmpMap = {};
1119
tmpList.splice(i, 1);
1220

1321
let b = (0 === nums[i]) ? 0 : -nums[i];
1422
let c = nums[i] + b;
1523
console.log(`i: ${i}, nums[i]: ${nums[i]}, b: ${b}, c: ${c}`);
24+
console.log("tmpList")
1625
console.log(tmpList)
1726

1827
// // Build a hash map except the current item in order to find the other 2 group mates.
@@ -24,9 +33,9 @@ const threeSum = (nums) => {
2433
result = findGroup(Math.min(...nums), Math.max(...nums), nums[i], b, c, tmpList, result);
2534
}
2635

27-
// console.log("result")
28-
// console.log(result)
29-
console.log(removeDuplicates(result))
36+
console.log("result")
37+
console.log(result)
38+
// console.log(removeDuplicates(result))
3039
// console.log([...new Set(result.map(JSON.stringify))].map(JSON.parse));
3140

3241
return removeDuplicates(result);
@@ -103,5 +112,5 @@ const findGroup = (min, max, a, b, c, list, result) => {
103112

104113
}
105114

106-
threeSum([0, 0, 0])
107-
// threeSum([-1,0,1,2,-1,-4])
115+
// threeSum([0, 0, 0])
116+
threeSum([-1, 0, 1, 2, -1, -4])

0 commit comments

Comments
 (0)