zoukankan      html  css  js  c++  java
  • 扫描线 leetcode 759

    /*
    // Definition for an Interval.
    
    class Interval {
    public:
        int start;
        int end;
    
        Interval() {}
    
        Interval(int _start, int _end) {
            start = _start;
            end = _end;
        }
    };
    */
    
    class Solution {
    public:
        vector<Interval*> employeeFreeTime(vector<vector<Interval*>> schedule) {
            vector<Interval*> all;
            for(auto i : schedule)
                all.insert(all.end(), i.begin(), i.end());   //将每个员工的工作区间加入到all中
            
            //将all里数据从小到大排序
            sort(all.begin(), all.end(), [](const Interval* a, const Interval* b){
                return a->start < b->start;
            });
            
            vector<Interval*> ans;
            int end = all.front()->end;
            for(auto busy : all){
                if(busy->start > end){
                    busy->start;
                    Interval* a = new Interval(end, busy->start); 
                    ans.push_back(a);
                }
                end = max(end, busy->end);
            }
            return ans;
        }
    };

    参考链接:https://zxi.mytechroad.com/blog/geometry/leetcode-759-employee-free-time/

    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    // Author: Huahua
    // Running time: 81 ms
    class Solution {
    public:
        vector<Interval> employeeFreeTime(vector<vector<Interval>>& schedule) {
          vector<Interval> all;
          for (const auto intervals : schedule)
            all.insert(all.end(), intervals.begin(), intervals.end());
          std::sort(all.begin(), all.end(), 
                    [](const Interval& a, const Interval& b){
                      return a.start < b.start;
                    });
          vector<Interval> ans;
          int end = all.front().end;
          for (const Interval& busy : all) {
            if (busy.start > end) 
              ans.emplace_back(end, busy.start);  
            end = max(end, busy.end);
          }
          return ans;
        }
    };
  • 相关阅读:
    短URL
    Linux安装MySQL
    Ubuntu中安装MySQL
    安装交叉工具链arm-linux-gcc
    Linux安装—IP设置
    Linux内核概述
    Bash变量
    Shell登陆
    Linux—查看远程Linux系统运行时间
    Linux—查看路由
  • 原文地址:https://www.cnblogs.com/Bella2017/p/11421441.html
Copyright © 2011-2022 走看看