Advertisement
Guest User

Untitled

a guest
Dec 7th, 2019
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.49 KB | None | 0 0
  1. // Runtime: 0 ms, faster than 100.00% of Java online submissions for Move Zeroes.
  2. // Memory Usage: 37.1 MB, less than 100.00% of Java online submissions for Move Zeroes.
  3. class Solution {
  4.     public void moveZeroes(int[] nums) {
  5.         int i = 0;
  6.         for(int num: nums){
  7.             if(num != 0){
  8.                 if (nums[i] != num) nums[i] = num;
  9.                 i++;
  10.             }
  11.         }
  12.         while(i < nums.length){
  13.             nums[i] = 0;
  14.             i++;
  15.         }
  16.     }
  17. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement