leetcode

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

1296.cpp (590B)


0 class Solution {
1 public:
2 bool isPossibleDivide(const vector<int> &nums, const int k) const {
3 map<int, int> um;
4 for (const int num : nums)
5 um[num]++;
6 for (auto start = begin(um); start != end(um); start++) {
7 const auto [crnt, step] = *start;
8 if (!step) continue;
9 for (int goal = crnt; goal < crnt + k; goal++) {
10 auto it = um.find(goal);
11 if (it == end(um) || it->second < step) return false;
12 it->second -= step;
13 }
14 }
15 return true;
16 }
17 };