Skip to content

Commit f66a25f

Browse files
solves 2 sum input II sorted array
1 parent 403b379 commit f66a25f

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
| 155 | [Min Stack](https://leetcode.com/problems/min-stack) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/MinStack.java) |
5151
| 157 | [Read N Characters Given Read4](https://leetcode.com/problems/read-n-characters-given-read4) | Easy |
5252
| 160 | [Intersection of Two Linked Lists](https://leetcode.com/problems/intersection-of-two-linked-lists) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/IntersectionOf2LinkedLists.java) |
53-
| 167 | [Two Sum II - Input Array is Sorted](https://leetcode.com/problems/two-sum-ii-input-array-is-sorted) | Easy |
53+
| 167 | [Two Sum II - Input Array is Sorted](https://leetcode.com/problems/two-sum-ii-input-array-is-sorted) | Easy |
5454
| 168 | [Excel Sheet Column Title](https://leetcode.com/problems/excel-sheet-column-title) | Easy |
5555
| 169 | [Majority Element](https://leetcode.com/problems/majority-element) | Easy |
5656
| 170 | [Two Sum III - Data Structure Design](https://leetcode.com/problems/two-sum-iii-data-structure-design) | Easy |

src/TwoSumIIInputArrayIsSorted.java

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import java.util.HashMap;
2+
import java.util.Map;
3+
4+
public class TwoSumIIInputArrayIsSorted {
5+
public int[] twoSum(int[] array, int target) {
6+
for (int i = 0, j = array.length - 1 ; i != j ; ) {
7+
if (array[i] + array[j] == target) {
8+
return new int[] {i + 1, j + 1};
9+
} else if (array[i] + array[j] < target) {
10+
i++;
11+
} else {
12+
j--;
13+
}
14+
}
15+
return new int[0];
16+
}
17+
}

0 commit comments

Comments
 (0)