Two lines & two passes 4ms C++ solution


  • 4
    M
    class Solution {
    public:
        void sortColors(vector<int>& nums) {
            auto iter = partition(nums.begin(), nums.end(), [](const int x) { return x < 1; });
            partition(iter, nums.end(), [](const int x) { return x < 2; });
        }
    };

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.