@@ -0,0 +1,1955 @@
+import org.junit.Test;%0A%0Aimport static org.junit.Assert.*;%0A%0A/**%0A * Given an array nums, write a function to move all 0's to the end of it while maintaining the relative order of the%0A * non-zero elements.%0A *%0A * For example, given nums = %5B0, 1, 0, 3, 12%5D, after calling your function, nums should be %5B1, 3, 12, 0, 0%5D.%0A *%0A * Note:%0A * You must do this in-place without making a copy of the array.%0A * Minimize the total number of operations.%0A *%0A * Tags: Array, Two Pointers%0A *%0A * Similar Problems: (E) Remove Element%0A */%0Apublic class MoveZeroes %7B%0A%0A    /**%0A     * move all positive to the front%0A     * add trailing zeroes%0A     */%0A    public void moveZeroes(int%5B%5D nums) %7B%0A        if (nums == null %7C%7C nums.length == 0) return;%0A        int count = 0;%0A        for (int n : nums) %7B%0A            if (n != 0) %7B%0A                nums%5Bcount%5D = n;%0A                count++;%0A            %7D%0A        %7D%0A        for (; count %3C nums.length; count++) %7B%0A            nums%5Bcount%5D = 0;%0A        %7D%0A    %7D%0A%0A    @Test%0A    public void tests() %7B%0A        MoveZeroes mz = new MoveZeroes();%0A        int%5B%5D nums = null;%0A        // null -%3E null%0A        mz.moveZeroes(nums);%0A        assertNull(nums);%0A        // empty -%3E empty%0A        nums = new int%5B%5D%7B%7D;%0A        mz.moveZeroes(nums);%0A        assertEquals(nums.length, 0);%0A        assertNotNull(nums);%0A        // %5B1%5D -%3E %5B1%5D%0A        nums = new int%5B%5D%7B1%7D;%0A        mz.moveZeroes(nums);%0A        assertArrayEquals(nums, new int%5B%5D%7B1%7D);%0A        // no zero, %5B1, 2, 3%5D -%3E %5B1, 2, 3%5D%0A        nums = new int%5B%5D%7B1, 2, 3%7D;%0A        mz.moveZeroes(nums);%0A        assertArrayEquals(nums, new int%5B%5D%7B1, 2, 3%7D);%0A        // all zeroes, %5B0, 0, 0%5D -%3E %5B0, 0, 0%5D%0A        nums = new int%5B%5D%7B0, 0, 0%7D;%0A        mz.moveZeroes(nums);%0A        assertArrayEquals(nums, new int%5B%5D%7B0, 0, 0%7D);%0A        // normal case, %5B0, 1, 0, 3, 12%5D -%3E %5B1, 3, 12, 0, 0%5D%0A        nums = new int%5B%5D%7B0, 1, 0, 3, 12%7D;%0A        mz.moveZeroes(nums);%0A        assertArrayEquals(nums, new int%5B%5D%7B1, 3, 12, 0, 0%7D);%0A    %7D%0A%7D%0A

add 283 Move Zeroes