Two Pointer로 풀이
class Solution {
public void moveZeroes(int[] nums) {
int i = 0;
for (int j = i+1; j < nums.length; j++) {
if(nums[i] == 0) {
if(nums[j] == 0) {
continue;
}else {
int tmp = nums[j];
nums[j] = nums[i];
nums[i] = tmp;
}
}
i++;
}
}
}
'JAVA > leetcode' 카테고리의 다른 글
[LeetCode Medium] Array - Container With Most Water !! - Two-pointer (0) | 2021.08.06 |
---|---|
[LeetCode] Array - Sort Array By Parity - Two-pointer (0) | 2021.08.05 |
[LeetCode] Array - Replace Elements with Greatest Element on Right Side (0) | 2021.08.05 |
[LeetCode] Array - Valid Mountain Array (0) | 2021.08.05 |
[LeetCode] Array - Check If N and Its Double Exist (0) | 2021.08.05 |