leetcode

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

0075.cpp (351B)


      1 class Solution {
      2   public:
      3     void sortColors(vector<int> &nums) const {
      4         int i = 0, j = 0, k = size(nums) - 1;
      5         while (j <= k) {
      6             if (nums[j] < 1)
      7                 swap(nums[i++], nums[j++]);
      8             else if (nums[j] > 1)
      9                 swap(nums[j], nums[k--]);
     10             else
     11                 j++;
     12         }
     13     }
     14 };