- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain001.java
More file actions
Latest commit
23 lines (21 loc) · 659 Bytes
/
Copy pathMain001.java
File metadata and controls
23 lines (21 loc) · 659 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
publicclassMain001 {
publicstaticvoidmain(String[] args){
int[] nums = newint[]{2,7,11,15};
inttarget = 9;
int[] res = twoSum(nums, target);
System.out.println(res[0] + "+" + res[1] + "=" + target);
}
publicstaticint[] twoSum(int[] nums, inttarget) {
int[] res = newint[2];
for (inti = 0; i < nums.length-1; i ++ ){
for (intj = i+1; j < nums.length; j++){
if (nums[i] + nums[j] == target){
res[0] = i;
res[1] = j;
returnres;
}
}
}
returnres;
}
}