Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <algorithm>
- class Solution {
- public:
- void sortColors(vector<int>& nums) {
- std::vector<int> counts(3);
- for (const auto& num : nums) {
- counts.at(num)++;
- }
- auto first = nums.begin();
- for (size_t i = 0; i < counts.size(); i++) {
- auto last = first + counts[i];
- std::fill(first, last, i);
- first = last;
- }
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement