Skip to content

Commit 66d3c1d

Browse files
committed
update two some problem
1 parent 3cac6eb commit 66d3c1d

1 file changed

Lines changed: 22 additions & 20 deletions

File tree

Programs/TwoSum.js

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -21,27 +21,29 @@
2121

2222

2323

24-
25-
2624
for (var i = 0; i < nums.length; i++) {
27-
2825
for (var n = 1; n < nums.length; n++) {
29-
30-
// console.log(nums[i] + nums[n])
31-
32-
if (nums[i] + nums[n] == target) {
33-
if (nums[i] == nums[n]) {
34-
35-
console.log([nums.indexOf(nums[i]), nums.indexOf(nums[i]) + 1])
36-
37-
} else {
38-
console.log([nums.indexOf(nums[i]), nums.indexOf(nums[n])])
39-
}
40-
41-
42-
26+
27+
if(nums[i] + nums[n] == target){
28+
if( nums[i]==nums[n] && nums.indexOf(nums[i]) == nums.indexOf(nums[n]) ){
29+
30+
let p = nums.indexOf(nums[n])+1
31+
32+
for (var m = p; m < nums.length; m++) {
33+
34+
if(nums[i]==nums[m]){
35+
return [i, m]
36+
}
37+
4338
}
44-
39+
40+
}else{
41+
return([ nums.indexOf(nums[i]), nums.indexOf(nums[n]) ])
42+
43+
}
44+
45+
}
46+
4547
}
46-
47-
}
48+
49+
}

0 commit comments

Comments
 (0)