283. Move Zeroes
class Solution {
public void moveZeroes(int[] nums) {
int zeroIndex = 0;
for (int i = 0; i < nums.length; i++) {
if (nums[i] != 0) {
if (i > zeroIndex) { // so smart, ๅฆๆๆฒๆ, ๅฐๆผ็ญๆผ็้ฝๆ่ฎ0
nums[zeroIndex] = nums[i];
nums[i] = 0;
}
zeroIndex++;
}
}
}
} if (nums[i] != 0) { // ๅฆๆๆฏ้ๆจฃ็่ณๆ, Input: [1,0,0,3,12], swap ๅฎ, 1้ๆฏๅๅไฝ็ฝฎ
swap(nums, zeroIndex, i);
zeroIndex++;
}PreviousLintcode - 1870 ยท Number of Substrings with All ZeroesNext1513. Number of Substrings With Only 1s
Last updated