-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTwoSum2.java
More file actions
33 lines (26 loc) · 745 Bytes
/
Copy pathTwoSum2.java
File metadata and controls
33 lines (26 loc) · 745 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package array;
/**
* @author qiaoying
* @date 2018/10/30 21:31
*/
public class TwoSum2 {
public static int[] twoSum(int[] numbers, int target) {
int[] result = new int[2];
for (int i = 0; i < numbers.length; i++){
for (int j = i + 1; j < numbers.length; j++){
if (numbers[i] + numbers[j] == target){
result[0] = i + 1;
result[1] = j + 1;
break;
}
}
}
return result;
}
public static void main(String[] args){
int[] array = {2, 3,4};
int target = 6;
int[] result = twoSum(array, target);
System.out.println(result[0] + " "+ result[1]);
}
}