Java PriorityQueue Solution O(logN) for seat() O(N) for leave()
seat(): Get the longest segment in pq, get the middle, update the pq\nleave(): Iterate the pq, get the two segments beside the p, update the pq\n\nSpent too muc
`seat()`: Get the longest segment in `pq`, get the middle, update the `pq`\n`leave()`: Iterate the `pq`, get the two segments beside the `p`, update the `pq`\n\nSpent too much time dealing with the the edge cases. So sad.\n\n```\nclass ExamRoom {\n    \n    private PriorityQueue<int[]> pq;\n    private int N;\n\n    public ExamRoom(int N) {\n        this.N = N;\n        pq = new PriorityQueue<>((a, b) -> {\n            if ((b[1] - b[0]) / 2 == (a[1] - a[0]) / 2) {\n                return a[0] - b[0];\n            }\n            return (b[1] - b[0]) / 2 - (a[1] - a[0]) / 2;\n        });\n    }\n    \n    public int seat() {\n        if (pq.size() == 0) {\n            pq.offer(new int[]{0, 2 * (N - 1)});\n            return 0;\n        } else {\n            int[] longest = pq.poll();\n            int result = longest[0] + (longest[1] - longest[0]) / 2;\n            if (result != 0) { // result = 0, we don\'t need to add the left side\n                pq.offer(new int[]{longest[0], result});\n            }\n            if (result != N - 1) { // result = N - 1, we don\'t need to add the right side\n                pq.offer(new int[]{result, longest[1]});\n            }\n            return result;\n        }\n    }\n    \n    public void leave(int p) {\n        if (pq.size() == 1 && (pq.peek()[1] >= N || pq.peek()[0] < 0)) { // Edge cases: Only [0, 2N] or [-N , N] in pq\n            pq.clear();\n            return;\n        }\n        int[] p1 = null, p2 = null; // p1: left side, p2: right side\n        for (int[] pair : pq) {\n            if (pair[1] == p) {\n                p1 = pair;\n            }\n            if (pair[0] == p) {\n                p2 = pair;\n            }\n        }\n        if (p1 != null) {\n            pq.remove(p1);\n        }\n        if (p2 != null) {\n            pq.remove(p2);\n        }\n        if (p1 == null || p1[0] < 0) { // No left side found or p is the left most position in current seats.\n            p1 = new int[]{-p2[1], p};\n        }\n        if (p2 == null || p2[1] >= N) { // No right side found or p is the right most position in current seats.\n            p2 = new int[]{p, p1[0] + 2 * (N - p1[0] - 1)};\n        }\n        pq.offer(new int[]{p1[0], p2[1]});\n    }\n}\n```
[]