class Solution {
public int[] sortArrayByParity(int[] nums) {
int left = 0, right = nums.length - 1;
while(left <= right){
if(nums[left] % 2 == 0) ++left;
else{
int temp = nums[left];
nums[left] = nums[right];
nums[right] = temp;
--right;
}
}
return nums;
}
}
955.按奇偶排序数组
最新推荐文章于 2024-08-21 23:40:55 发布