leetcodeSolution to some Leetcode problems written in C++ |
git clone git://git.dimitrijedobrota.com/leetcode.git |
Log | Files | Refs | README | LICENSE |
3111.cpp (481B)
0 class Solution { 1 public: 2 int minRectanglesToCoverPoints(const vector<vector<int>> &points, int w) const { 3 set<int> st; 4 5 for (const auto &point : points) 6 st.insert(point[0]); 7 if (w == 0) return size(st); 8 9 int res = 1, prev = *st.begin(); 10 11 while (true) { 12 auto it = st.upper_bound(prev + w); 13 if (it == st.end()) break; 14 prev = *it; 15 res++; 16 } 17 18 return res; 19 } 20 };