Open fly0o0 opened 4 years ago
/**
* @param {number[]} nums
* @return {number[]}
*/
var exchange = function(nums) {
let low = 0
let fast = 0
while (fast < nums.length) {
if (nums[fast] % 2 != 0) {
// 把奇数往前交换
[nums[fast], nums[low]] = [nums[low], nums[fast]]
// 奇数部分增加1
low++
}
// 遍历增加1
fast++
}
return nums
};