File tree 2 files changed +67
-0
lines changed 2 files changed +67
-0
lines changed Original file line number Diff line number Diff line change
1
+ public class Solution
2
+ {
3
+ public ListNode DeleteDuplicates ( ListNode head )
4
+ {
5
+ int currentValue = head . val ;
6
+ int nextValue = 0 ;
7
+
8
+
9
+ if ( head == null || head . next == null )
10
+ { return head ; }
11
+
12
+ ListNode copyHead = head ;
13
+ while ( copyHead . next != null )
14
+ {
15
+ currentValue = copyHead . val ;
16
+ nextValue = copyHead . next . val ;
17
+ if ( currentValue == nextValue )
18
+ {
19
+ copyHead . next = copyHead . next . next ;
20
+ }
21
+ else
22
+ {
23
+ copyHead = copyHead . next ;
24
+ }
25
+ }
26
+
27
+ return head ;
28
+ }
29
+ }
Original file line number Diff line number Diff line change
1
+ public class Solution
2
+ {
3
+ public int [ ] SortArrayByParity ( int [ ] A )
4
+ {
5
+ if ( A == null && A . Length == 0 )
6
+ {
7
+ return A ;
8
+ }
9
+ int indexHead = 0 ;
10
+ int indexTail = A . Length - 1 ;
11
+ int tempValue = 0 ;
12
+ while ( indexHead < indexTail )
13
+ {
14
+ if ( A [ indexHead ] % 2 == 1 && A [ indexTail ] % 2 == 0 )
15
+ {
16
+ tempValue = A [ indexHead ] ;
17
+ A [ indexHead ] = A [ indexTail ] ;
18
+ A [ indexTail ] = tempValue ;
19
+ indexHead ++ ;
20
+ indexTail -- ;
21
+ }
22
+ else if ( A [ indexHead ] % 2 == 0 && A [ indexTail ] % 2 == 1 )
23
+ {
24
+ indexHead ++ ;
25
+ indexTail -- ;
26
+ }
27
+ else if ( A [ indexHead ] % 2 == 1 )
28
+ {
29
+ indexTail -- ;
30
+ }
31
+ else if ( A [ indexTail ] % 2 == 0 )
32
+ {
33
+ indexHead ++ ;
34
+ }
35
+ }
36
+ return A ;
37
+ }
38
+ }
You can’t perform that action at this time.
0 commit comments