clean Java TreeSet solution
\'\'\'\nclass ExamRoom {\n    TreeSet set;\n    int n;\n    public ExamRoom(int N) {\n        set = new TreeSet();\n        n = N;\n    }\n    \n    public int 
\'\'\'\nclass ExamRoom {\n    TreeSet<Integer> set;\n    int n;\n    public ExamRoom(int N) {\n        set = new TreeSet();\n        n = N;\n    }\n    \n    public int seat() {        \n        if(set.size() == 0){\n            set.add(0);\n            return 0;\n        }                \n        \n        int gap = set.first(), sit = 0, pre = set.first();\n        for(int cur: set){\n            if(gap < (cur - pre) / 2){\n                gap = (cur - pre) / 2;\n                sit = (cur + pre) / 2;\n            }\n            pre = cur;\n        }\n        if(n - 1 - pre > gap)\n            sit = n - 1;\n        \n        set.add(sit);\n        return sit;\n    }\n    \n    public void leave(int p) {\n        set.remove(p);\n    }\n}\n\'\'\'\nthe idea is to iterate the sorted set, find out the biggest gap and then the sit spot would be the middle of the gap.\n\nfor example: \n0, 9 -> the gap is (9 - 0) / 2 = 4, the seat would be (0 + 9) / 2 = 4\n0, 4, 9 -> two gaps are same, pick the front gap\n0, 2, 4, 9 ->  gap between 4 and 9 is bigger\n\n0,1,2,3,4,5,6,7,8,9\nthe reason we divde (cur - pre) by 2 is to make the seat always closer to previous occupied seat. Even though 9 - 4 > 4 - 0, the shortest spare seats are same.\n\n
[]