- Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathTwoSum.java
26 lines (23 loc) · 810 Bytes
/
TwoSum.java
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
importjava.util.*;
importjava.io.*;
classMain {
publicstaticStringTwoSum(int[] arr) {
StringBuilderoutput = newStringBuilder();
for (inti = 1; i < arr.length; i++) {
for (intj = i + 1; j < arr.length; j++) {
if (arr[i] + arr[j] == arr[0]) {
if (output.length() > 0) {
output.append(" ");
}
output.append(arr[i]).append(",").append(arr[j]);
}
}
}
returnoutput.length() == 0 ? "-1" : output.toString();
}
publicstaticvoidmain (String[] args) {
// keep this function call here
Scanners = newScanner(System.in);
System.out.print(TwoSum(s.nextLine()));
}
}