classSolution { public: boolisNStraightHand(vector<int>& hand, int W){ div_t di = div(hand.size(), W); if (di.rem) { returnfalse; }
map<int, int> hds; for (auto v : hand) { ++hds[v]; }
while (!hds.empty()) { auto it = *hds.begin(); for (int l = it.second, b = it.first, e = it.first + W; b < e; ++b) { hds[b] -= l; if (hds[b] < 0) { returnfalse; } elseif (hds[b] == 0) { hds.erase(b); } } }