题解 | #主持人调度(二)#

主持人调度(二)

https://www.nowcoder.com/practice/4edf6e6d01554870a12f218c94e8a299

本质上是看一组区间数组中的相交数组的个数。

static const auto io_sync_off = []() {
    // turn off sync
    std::ios::sync_with_stdio(false);
    // untie in/out streams
    std::cin.tie(nullptr);
    return nullptr;
}
();
class Solution {
  public:
    int minmumNumberOfHost(int n, vector<vector<int> >& startEnd) {
        vector<int> sortStart(n), sortEnd(n);
        for (int i = 0; i < n; i++) {
            sortStart[i] = startEnd[i][0];
            sortEnd[i] = startEnd[i][1];
        }
        sort(sortStart.begin(), sortStart.end());
        sort(sortEnd.begin(), sortEnd.end());
        int count = 0;
        for (int i = 0, j = 0; i < n; i++) {
            if (sortStart[i] >= sortEnd[j]) {
                j++;
            } else {
                count++;
            }
        }
        return count;
    }
};

全部评论

相关推荐

头顶尖尖的程序员:我也是面了三四次才放平心态的。准备好自我介绍,不一定要背熟,可以记事本写下来读。全程控制语速,所有问题都先思考几秒,不要急着答,不要打断面试官说话。
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务