C++ Set, O(n) seat and O(log(n)) leave
\nclass ExamRoom {\npublic:\n    ExamRoom(int N) {\n        n = N;\n    }\n    \n    int seat() {\n        //If seats are all availble, just seat at 0\n        
```\nclass ExamRoom {\npublic:\n    ExamRoom(int N) {\n        n = N;\n    }\n    \n    int seat() {\n        //If seats are all availble, just seat at 0\n        if (seats.empty()) {\n            seats.insert(0);\n            return 0;\n        }\n        \n        //Consider middle seats \n        int res;\n        auto it = seats.begin();\n        //If no one seats at 0, initialize position 0 as result\n        if (*it != 0) {\n            res = 0;\n        }\n        int diff = *it - 0;                 //diff is the maximum distance to its closest neighbor\n        it++;                               //Here it++, because we should calculate from second postion\n        while (it != seats.end()) {\n            int dis = *it - *prev(it);\n            if (dis / 2 > diff) {           //If dis is greater than diff, just update res and diff\n                res = *prev(it) + dis / 2;\n                diff = dis / 2;\n            }\n            it++;\n        }\n        //Consider last seats\n        if (n - 1 - *prev(it) > diff) {\n            res = n - 1;\n        }\n        seats.insert(res);\n        return res;\n    }\n    \n    void leave(int p) {\n        seats.erase(p);\n    }\nprivate:\n    set<int> seats;\n    int n;\n};\n\n```
[]