Share my solution, which make me know lumoto and hoarn partition's difference

  • 0
    class Solution {
        void moveZeroes(vector<int>& a) {
            int n = a.size(), i=0, j;
            //a[0..i-1]: 1, a[i, j-1]: 0
            //i=0, j=0
            for(int j=0;j<n;j++){
                swap(a[i++], a[j]);

    lumoto partition, which swap is more than hoarn, but coding easy, and stable parition : )

Log in to reply

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