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

主持人调度(二)

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;
    }
};

全部评论

相关推荐

什么时候才能有offer啊_:十年前我还在刺激战场研究跳伞的底层原理呢
投递牛客等公司10个岗位
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务