We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 3cac6eb commit 66d3c1dCopy full SHA for 66d3c1d
1 file changed
Programs/TwoSum.js
@@ -21,27 +21,29 @@
21
22
23
24
-
25
26
for (var i = 0; i < nums.length; i++) {
27
28
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
+
+ if(nums[i] + nums[n] == target){
+ if( nums[i]==nums[n] && nums.indexOf(nums[i]) == nums.indexOf(nums[n]) ){
+ let p = nums.indexOf(nums[n])+1
+ for (var m = p; m < nums.length; m++) {
+ if(nums[i]==nums[m]){
+ return [i, m]
+ }
43
}
44
+ }else{
+ return([ nums.indexOf(nums[i]), nums.indexOf(nums[n]) ])
45
46
47
-}
48
49
0 commit comments