Skip to content

Commit 2d05845

Browse files
committed
add q167
1 parent cd6c12f commit 2d05845

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

101-200/167-two-sum-ii.js

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
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+
};

README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,5 @@ Solutions of all the questions from Leetcode in JavaScript.
1111
- 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)
1212
- 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)
1313
- 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)

0 commit comments

Comments
 (0)