File tree Expand file tree Collapse file tree 1 file changed +47
-0
lines changed
C#/LeetCodeResolves/LeetCodeResolves/Arrays/MoveZeroes Expand file tree Collapse file tree 1 file changed +47
-0
lines changed Original file line number Diff line number Diff line change
1
+ using System ;
2
+ using System . Collections . Generic ;
3
+ using System . Text ;
4
+
5
+ namespace LeetCodeResolves . Arrays . MoveZeroes
6
+ {
7
+ class Program
8
+ {
9
+ static void Main ( string [ ] args )
10
+ {
11
+ var arr = new int [ ] { 0 , 3 , 2 , 1 } ;
12
+ MoveZeroes ( arr ) ;
13
+
14
+ Console . ReadLine ( ) ;
15
+ }
16
+
17
+ static void MoveZeroes ( int [ ] arr )
18
+ {
19
+ var slow = 0 ;
20
+ var fast = 0 ;
21
+ while ( fast < arr . Length )
22
+ {
23
+ if ( arr [ slow ] == 0 )
24
+ {
25
+ while ( fast < arr . Length && arr [ fast ] == 0 )
26
+ {
27
+ fast ++ ;
28
+ }
29
+
30
+ if ( fast == arr . Length )
31
+ {
32
+ return ;
33
+ }
34
+ else
35
+ {
36
+ var temp = arr [ slow ] ;
37
+ arr [ slow ] = arr [ fast ] ;
38
+ arr [ fast ] = temp ;
39
+ }
40
+ }
41
+
42
+ slow ++ ;
43
+ fast ++ ;
44
+ }
45
+ }
46
+ }
47
+ }
You can’t perform that action at this time.
0 commit comments