Finally met a water problem, go to sleep ~
Move ZeroesTotal accepted:37369 Total submissions:88383 difficulty:easy
Given an array nums , write a function to move all's to the 0 end of it while maintaining the relative order of the No N-zero elements.
For example, given nums = [0, 1, 0, 3, 12] , after calling your function, nums should is [1, 3, 12, 0, 0] .
Note:
- You must does this in-place without making a copy of the array.
- Minimize The total number of operations.
Another point, I write code, with C and C + + is very unfamiliar, rather than Java convenience. This shows the need to review!
Java:
1 Public classSolution {2 Public voidMovezeroes (int[] nums) {3 for(inti = 0; i < nums.length; i++) {4 if(Nums[i] = = 0) {5 for(intj = i + 1; J < Nums.length; J + +) {6 if(nums[j]! = 0) {7Nums[i] =Nums[j];8NUMS[J] = 0;9 Ten Break; One } A } - } - } the - } -}
"5_283" Move zeroes