LeetCode problem#283
Move Zeroes
Solved in 1 languageJava
Solution
16 lines
1class Solution {
2 public void moveZeroes(int[] nums) {
3 int j = 0;
4 for (int i = 0; i < nums.length; i++) {
5 if (nums[i] != 0) {
6 nums[j] = nums[i];
7 j++;
8 }
9 }
10
11 while (j < nums.length) {
12 nums[j] = 0;
13 j++;
14 }
15 }
16}Want a walkthrough of this Java solution?
Get a step-by-step explanation of the idea behind the code.
Problem statements belong to LeetCode and are on leetcode.com. We're not affiliated with LeetCode.