a very simple solution by java


  • 0
    K

    public class Solution {
    public void moveZeroes(int[] array) {
    int count0=0;
    for (int i=0;i<array.length;i++){
    if (array[i]==0){
    count0++;
    }
    }
    int j=0;
    for (int i=0;i<array.length;i++){
    if (array[i]!=0){
    array[j]=array[i];
    j++;
    }
    }
    for (int i=array.length-count0;i<array.length;i++){
    array[i]=0;
    }
    }

    }


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.