sort array by parity c++ I can not understand

class Solution {
public:
vector sortArrayByParity(vector& nums) {

    int i = 0;
    int j = nums.size() - 1;
    int tmp;
    
    while (i < j) {
        if (nums[i] % 2 == 0 && nums[j] % 2 != 0) { 
            i++;
            j--;

        } else if (nums[i] % 2 == 0 && nums[j] % 2 == 0) {
            i++;

        } else if (nums[i] % 2 != 0 && nums[j] % 2 != 0) {
            j--;

        } else if (nums[i] % 2 != 0 && nums[j] % 2 == 0) {
            tmp = nums[i];
            nums[i] = nums[j];
            nums[j] = tmp;
            i++;
            j--;

        }
            
    }
                                                  
    return nums;
}

};

in the last else if wheter you increment i and decrement j or not your code is still accepted. I do not understand if we dont increment and decrement them how can we continue. some guy from youtube also doesnt increment or decrement that part. but it accepts anyways.

Comments (0)