Java TreeSet
\nclass ExamRoom {\n    private int N;\n    private TreeSet<Integer> treeSet;\n    public ExamRoom(int N) {\n        this.N = N;\n        this.treeSet = new Tre
```\nclass ExamRoom {\n    private int N;\n    private TreeSet<Integer> treeSet;\n    public ExamRoom(int N) {\n        this.N = N;\n        this.treeSet = new TreeSet<>();\n    }\n    \n    public int seat() {\n        int p = 0;\n        if(treeSet.size() > 0) {\n            int dist = treeSet.first();\n            Integer prev = null;            \n            for(int s: treeSet){\n                if(prev != null){\n                    int d = (s - prev)/2;\n                    if(d > dist) {\n                        dist = d;\n                        p = prev + d;\n                    }\n                }\n                prev = s;\n            }\n            if(N - 1 - treeSet.last() > dist) {\n                p = N - 1;\n            }            \n        }\n        treeSet.add(p);\n        return p;\n    }\n    \n    public void leave(int p) {\n        treeSet.remove(p);\n    }\n}\n```
[]