-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTest.java
More file actions
49 lines (46 loc) · 1.46 KB
/
Copy pathTest.java
File metadata and controls
49 lines (46 loc) · 1.46 KB
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
/**
* @Author: shiwei10
* @Date: 2024/4/22 18:46
*/
public class Test {
public static List<List<Integer>> getResult(int[] input) {
List<List<Integer>> result = new ArrayList<>();
Arrays.sort(input);
for (int i = 0; i < input.length; i++) {
if (input[i] > 0) {
return result;
}
if (i > 0 && input[i - 1] == input[i]) {
continue;
}
int right = input.length - 1;
int left = i + 1;
while (left < right) {
if (input[i] + input[left] + input[right] == 0) {
List<Integer> temp = new ArrayList<>();
temp.add(input[i]);
temp.add(input[left]);
temp.add(input[right]);
result.add(temp);
while (left < right && input[right] == input[right - 1]) {
right--;
}
while (left < right && input[left] == input[left + 1]) {
left++;
}
} else if (input[i] + input[left] + input[right] < 0) {
left++;
} else {
right--;
}
}
}
return result;
}
public static void main(String[] args) {
System.out.println("test");
}
}