Advertisement
Guest User

Untitled

a guest
Feb 26th, 2020
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.42 KB | None | 0 0
  1. #include <algorithm>
  2.  
  3. class Solution {
  4. public:
  5.     void sortColors(vector<int>& nums) {
  6.         std::vector<int> counts(3);
  7.         for (const auto& num : nums) {
  8.             counts.at(num)++;
  9.         }
  10.         auto first = nums.begin();
  11.         for (size_t i = 0; i < counts.size(); i++) {
  12.             auto last = first + counts[i];
  13.             std::fill(first, last, i);
  14.             first = last;
  15.         }
  16.     }
  17. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement