Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 44e0bac

Browse files
Two Sum II - Input Array Is Sorted
1 parent 783fffb commit 44e0bac

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
Link: https://leetcode.com/problems/two-sum-ii-input-array-is-sorted/
2+
Language: C#
3+
4+
5+
6+
7+
8+
9+
10+
public class Solution {
11+
public int[] TwoSum(int[] numbers, int target)
12+
{
13+
int index1 = 0, index2 = numbers.Length - 1;
14+
15+
while (index1 < index2)
16+
{
17+
if (numbers[index1] + numbers[index2] == target)
18+
return [index1 + 1, index2 + 1];
19+
else if (numbers[index1] + numbers[index2] > target)
20+
index2--;
21+
else
22+
index1++;
23+
}
24+
25+
return [-1, -1];
26+
}
27+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /