We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 6d98c92 commit 2f6584cCopy full SHA for 2f6584c
Array/167.two-sum-ii-input-array-is-sorted.java
@@ -0,0 +1,27 @@
1
+/*
2
+ * @lc app=leetcode id=167 lang=java
3
+ *
4
+ * [167] Two Sum II - Input array is sorted
5
+ */
6
+
7
+// @lc code=start
8
+class Solution {
9
+ public int[] twoSum(int[] numbers, int target) {
10
+ int start = 0;
11
+ int end = numbers.length - 1;
12
13
+ while (start <= end) {
14
+ int sum = numbers[start] + numbers[end];
15
+ if (sum == target) {
16
+ return new int[]{start + 1, end + 1};
17
+ } else if (sum < target) {
18
+ start++;
19
+ } else {
20
+ end--;
21
+ }
22
23
+ return new int[]{-1, -1};
24
25
+}
26
+// @lc code=end
27
0 commit comments