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

Appearance settings

Latest commit

 

History

History
History
23 lines (22 loc) · 850 Bytes

File metadata and controls

23 lines (22 loc) · 850 Bytes
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
package ch18;
public class P73_1 {
public int[] twoSum(int[] numbers, int target) {
// 왼쪽 포인터는 가장 좌측 지정
int left = 0;
// 오른쪽 포인터는 가장 우측 지정
int right = numbers.length - 1;
// 왼쪽 포인터가 오른쪽 포인터와 작다면 계속 탐색
while (left != right) {
// 합이 target보다 작으면 왼쪽 포인터를 오른쪽으로 이동
if (numbers[left] + numbers[right] < target) {
left += 1;
// 합이 target보다 크면 오른쪽 포인터를 왼쪽으로 이동
} else if (numbers[left] + numbers[right] > target) {
right -= 1;
} else {
return new int[]{left + 1, right + 1};
}
}
return null;
}
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.