```
public class Solution {
public void moveZeroes(int[] nums) {
if (nums != null) {
for (int i = 0, j = 0; j < nums.length; i++,j++) {
if (nums[i] == 0) {
j = indexOfNonZero(nums, i + 1);
if (j < nums.length) {
nums[i] = nums[j];
nums[j] = 0;
}
}
}
}
}
private int indexOfNonZero(int nums[], int startIndex) {
int i = startIndex;
for(; i < nums.length; i++) {
if (nums[i] != 0) {
return i;
}
}
return i;
}
}
```

I think my solution :

- Space Complexity : O(1).
- Time Complexity: O(n).

But my run time just beats only 14% of java submissions.

Why? Very thankful for your reply.