- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathM.java
More file actions
Latest commit
35 lines (30 loc) · 895 Bytes
/
Copy pathM.java
File metadata and controls
35 lines (30 loc) · 895 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
34
35
importjava.util.*;
/**
* Created by jianghan on 2017/2/20.
*/
publicclassM {
int[] solve(int[] data, intgoal) {
Set<Integer> set = newHashSet<>(data.length);
List<Integer> list = newArrayList<>();
for (inti = 0; i < data.length; i++) {
set.add(data[i]);
list.add(data[i]);
}
Collections.sort(list);
for (inta = 0; a < list.size(); a++) {
intx = goal - list.get(a);
if (x / 2 < list.get(a)) {
break;
}
for (intb = a + 1; b < list.size(); b++) {
intc = x - list.get(b);
if (list.get(b) < c && set.contains(c)) {
returnnewint[]{list.get(a), list.get(b), c};
}
}
}
returnnewint[3];
}
publicstaticvoidmain(String[] args) {
}
}