[Java] Only one TreeSet solution | O(N) for seat() & O(logN) for leave()
\nclass ExamRoom {\n    \n    TreeSet<Integer> set;\n    int n;\n\n    public ExamRoom(int n) {\n        set = new TreeSet<>();\n        this.n = n-1;\n    }\n 
```\nclass ExamRoom {\n    \n    TreeSet<Integer> set;\n    int n;\n\n    public ExamRoom(int n) {\n        set = new TreeSet<>();\n        this.n = n-1;\n    }\n    \n    public int seat() {\n        //Add first seat if all seats are empty\n        if (set.size() == 0) {\n            set.add(0);\n            return 0;\n        }\n        \n        //Get first seat and compute difference between 0 and first seat\n        int left = set.first();\n        int diff = left;\n        int max = 0;\n        \n        int mid;\n        \n        //Traverse set and the capture two intervals in which seats are empty\n        //The max distance would be mid of two intervals in which seats are empty\n        for (Integer right : set) {\n            if (right == left) continue;\n            mid = left + (right-left)/2;\n            if (diff < Math.min(mid-left, right-mid) && !set.contains(mid)) {\n                diff = Math.min(mid-left, right-mid);\n                max = mid;\n            }\n            left = right;\n        }\n        \n        //Get last seat and compute difference between n and last seat\n        int last = set.last();\n        if (n-last > diff) max = n;\n        \n        //Add the captured seat to set\n        set.add(max);\n        return max;\n    }\n    \n    public void leave(int p) {\n        set.remove(p);\n    }\n}\n```\n\nPlease **comment** and **upvote** if you like the solution
['Tree', 'Binary Tree', 'Ordered Set', 'Java']