模拟维护离开椅子时间,采用轮训的方法或者用小根堆优化即可。
class Solution {
public:
int smallestChair(vector<vector<int>>& times, int targetFriend) {
int arrival = times[targetFriend][0], leavingi = times[targetFriend][1];
sort(times.begin(), times.end());
int n = times.size();
vector<int> leavetimes(n);
for (auto time : times) {
int idx = -1;
for (int i = 0; i < n; i++) {
if (time[0] >= leavetimes[i]) {
leavetimes[i] = time[1];
idx = i;
break;
}
}
if (time[0] == arrival) {
return idx;
}
}
return -1;
}
};