当前位置:网站首页>An Offer 21. Adjust the array in order to make odd in even the front (loop invariant)

An Offer 21. Adjust the array in order to make odd in even the front (loop invariant)

2022-08-09 13:54:00 to raise pigs

class Solution {
    
    public int[] exchange(int[] nums) {
    
        int n = nums.length;
        int i = -1, j = 0;
        for(; j < n; j++) {
    
            if(nums[j] % 2 == 1) {
    
                int t = nums[++i];
                nums[i] = nums[j];
                nums[j] = t;                
            }
        }
        return nums;
    }
}
原网站

版权声明
本文为[to raise pigs]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/221/202208091244510712.html