You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

21 lines
333 B

2 years ago
package class33;
public class Problem_0283_MoveZeroes {
public static void moveZeroes(int[] nums) {
int to = 0;
for (int i = 0; i < nums.length; i++) {
if (nums[i] != 0) {
swap(nums, to++, i);
}
}
}
public static void swap(int[] arr, int i, int j) {
int tmp = arr[i];
arr[i] = arr[j];
arr[j] = tmp;
}
}