leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE

3111.cpp (481B)


      1 class Solution {
      2   public:
      3     int minRectanglesToCoverPoints(const vector<vector<int>> &points, int w) const {
      4         set<int> st;
      5 
      6         for (const auto &point : points)
      7             st.insert(point[0]);
      8         if (w == 0) return size(st);
      9 
     10         int res = 1, prev = *st.begin();
     11 
     12         while (true) {
     13             auto it = st.upper_bound(prev + w);
     14             if (it == st.end()) break;
     15             prev = *it;
     16             res++;
     17         }
     18 
     19         return res;
     20     }
     21 };