Simple C++ solution
\nclass ExamRoom {\npublic:\n    \n    vector<int> seats;\n    int num;\n    \n    ExamRoom(int N) {\n        num = N;\n    }\n    \n    int seat() {\n        i
```\nclass ExamRoom {\npublic:\n    \n    vector<int> seats;\n    int num;\n    \n    ExamRoom(int N) {\n        num = N;\n    }\n    \n    int seat() {\n        if (seats.empty()){\n            seats.push_back(0); return 0;\n        }else{\n            int maxSeat = 0, maxDis = seats[0], toinsert = 0;\n            for (int i=0; i<seats.size()-1; i++){\n                if ((seats[i+1]-seats[i])/2 > maxDis){\n                    maxDis = (seats[i+1]-seats[i])/2;\n                    maxSeat = (seats[i+1]+seats[i])/2;\n                    toinsert = i+1;\n                }\n            }\n            if (num-1-seats.back()>maxDis){\n                seats.push_back(num-1);\n                return num-1;\n            }else{\n                seats.insert(seats.begin()+toinsert, maxSeat);\n                return maxSeat;   \n            }\n        }\n    }\n    \n    void leave(int p) {\n        int i=0, j=seats.size()-1, mid;\n        while (i<=j){\n            mid = (i+j)/2;\n            if (seats[mid]==p){\n                seats.erase(seats.begin()+mid); return;\n            }else if (seats[mid]>p) j=mid-1;\n            else i=mid+1;\n        }\n        return;\n    }\n};\n```
[]