2
public static class Pair {12
public int[][] outerTrees(int[][] trees) {13
List<Pair> points = new ArrayList<>();14
for (int[] point : trees) {15
points.add(new Pair(point[0], point[1]));18
List<Pair> res = new ArrayList<>();19
if (points.size() == 1) {22
int n = points.size();23
Collections.sort(points, (a, b) -> a.y == b.y ? a.x - b.x : a.y - b.y);24
HashSet<ArrayList<Integer>> dup = new HashSet<>();25
Stack<Pair> hull = new Stack<>();27
hull.push(points.get(0));28
hull.push(points.get(1));30
for (int i = 2; i < n; i++) {31
Pair top = hull.pop();32
while (!hull.isEmpty() && ccw(hull.peek(), top, points.get(i)) < 0) {36
hull.push(points.get(i));38
for (int i = n - 2; i >= 0; i--) {39
Pair top = hull.pop();40
while (!hull.isEmpty() && ccw(hull.peek(), top, points.get(i)) < 0) {44
hull.push(points.get(i));48
ArrayList<Integer> tmp = new ArrayList<>();51
if (dup.contains(tmp)) continue;56
int[][] ans = new int[res.size()][2];67
public int ccw(Pair a, Pair b, Pair c) {68
double cp = (b.x - a.x) * (c.y - a.y) - (b.y - a.y) * (c.x - a.x);69
if (cp < 0) return -1;70
else if (cp > 0) return 1;