File tree 2 files changed +22
-1
lines changed
2 files changed +22
-1
lines changed Original file line number Diff line number Diff line change
1
+ /*
2
+ Author :- Rishabh Jain <contact@rishabh1403.com>
3
+ Solution for :- https://leetcode.com/problems/two-sum-ii-input-array-is-sorted/
4
+ blog for this code :- https://rishabh1403.com/leetcode-solution-of-two-sum-ii-in-javascript
5
+ */
6
+
7
+
8
+ var twoSum = function ( numbers , target ) {
9
+ let i = 0 ;
10
+ let j = numbers . length - 1 ;
11
+ while ( i !== j ) {
12
+ if ( numbers [ i ] + numbers [ j ] > target ) {
13
+ j -- ;
14
+ } else if ( numbers [ i ] + numbers [ j ] < target ) {
15
+ i ++ ;
16
+ } else {
17
+ return [ i + 1 , j + 1 ] ;
18
+ }
19
+ }
20
+ } ;
Original file line number Diff line number Diff line change @@ -11,4 +11,5 @@ Solutions of all the questions from Leetcode in JavaScript.
11
11
- 1.Two Sum - [ Question] ( https://leetcode.com/problems/two-sum/ ) | [ Source Code] ( https://github.com/rishabh1403/leetcode-javascript-solutions/blob/master/1-100/1-two-sum.js ) | [ Blog] ( https://rishabh1403.com/leetcode-solution-of-two-sum-in-javascript )
12
12
- 7.Reverse Integer - [ Question] ( https://leetcode.com/problems/reverse-integer/ ) | [ Source Code] ( https://github.com/rishabh1403/leetcode-javascript-solutions/blob/master/1-100/7-reverse-integer.js ) | [ Blog] ( https://rishabh1403.com/leetcode-solution-of-reverse-integer-in-javascript )
13
13
- 9.Palindrome Number - [ Question] ( https://leetcode.com/problems/palindrome-number/ ) | [ Source Code] ( https://github.com/rishabh1403/leetcode-javascript-solutions/blob/master/1-100/9-palindrome-number.js ) | [ Blog] ( https://rishabh1403.com/leetcode-solution-of-palindrome-number-in-javascript )
14
- - 20.Valid Parentheses - [ Question] ( https://leetcode.com/problems/valid-parentheses/ ) | [ Source Code] ( https://github.com/rishabh1403/leetcode-javascript-solutions/blob/master/1-100/20-valid-parentheses.js ) | [ Blog] ( https://rishabh1403.com/leetcode-solution-of-valid-parentheses-in-javascript )
14
+ - 20.Valid Parentheses - [ Question] ( https://leetcode.com/problems/valid-parentheses/ ) | [ Source Code] ( https://github.com/rishabh1403/leetcode-javascript-solutions/blob/master/1-100/20-valid-parentheses.js ) | [ Blog] ( https://rishabh1403.com/leetcode-solution-of-valid-parentheses-in-javascript )
15
+ - 167.Two Sum-II - [ Question] ( https://leetcode.com/problems/two-sum-ii-input-array-is-sorted/ ) | [ Source Code] ( https://github.com/rishabh1403/leetcode-javascript-solutions/blob/master/1-100/20-valid-parentheses.js ) | [ Blog] ( https://rishabh1403.com/leetcode-solution-of-two-sum-ii-in-javascript )
You can’t perform that action at this time.
0 commit comments