- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1TwoSum.java
More file actions
Latest commit
23 lines (21 loc) · 642 Bytes
/
Copy path1TwoSum.java
File metadata and controls
23 lines (21 loc) · 642 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
importjava.io.*;
classSolution {
publicint[] twoSum(int[] nums, inttarget) {
for (inti = 0; i < nums.length; i++) {
for (intj = i+1; j < nums.length; j++) {
if ((nums[i] + nums[j]) == target) {
returnnewint[] { i, j };
}
}
}
returnnewint[] { -1, -1 };
}
publicstaticvoidmain(String[] args) throwsIOException {
Solutionobj = newSolution();
int[] num = { 3,2,4};
int[] y = obj.twoSum(num,6);
for (inti = 0;i<y.length;i++) {
System.out.print(y[i]+" ");
}
}
}