We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent c754ccb commit 527b118Copy full SHA for 527b118
move_zeroes_283/solution.go
@@ -1,9 +1,9 @@
1
package move_zeroes_283
2
3
-// Note: tricky problem!
4
// Ex: [1,0,0,3,12]
5
-// i
6
-// p
+//
+// i
+// p
7
func moveZeroes(nums []int) {
8
placement := 0
9
for i := 0; i < len(nums); i++ {
@@ -15,3 +15,17 @@ func moveZeroes(nums []int) {
15
}
16
17
18
+
19
+func moveZeroes2(nums []int) {
20
+ i, j := 0, 1
21
+ for j < len(nums) {
22
+ if nums[i] != 0 {
23
+ i++
24
+ }
25
+ if nums[i] == 0 && nums[j] != 0 {
26
+ nums[i], nums[j] = nums[j], nums[i]
27
28
29
+ j++
30
31
+}
0 commit comments