File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ package com .paula .algorithmsAndDataStructure .leetCode_83 ;
2+
3+ public class LeetCode_083_039 {
4+ public ListNode deleteDuplicates (ListNode head ) {
5+ if (head == null ) return null ;
6+
7+ ListNode p = head ;
8+ ListNode q = null ;
9+ while (p .next != null ) {
10+ if (p .val == p .next .val ) {
11+ if (q == null || (q != null && q .val != p .val )) {
12+ q = p ;
13+ }
14+ }else {
15+ if (q != null && q .val == p .val ) {
16+ q .next = p .next ;
17+ }
18+ }
19+ p = p .next ;
20+ }
21+
22+ if (q != null && p .val == q .val && p .next == null ) {
23+ q .next = null ;
24+ }
25+ return head ;
26+ }
27+
28+ }
Original file line number Diff line number Diff line change 1+ package com .paula .algorithmsAndDataStructure ;
2+
3+ public class LeetCode_922_039 {
4+ public int [] sortArrayByParityII (int [] A ) {
5+ int len = A .length ;
6+ int i =0 ; //偶数下标
7+ int j =i +1 ; //奇数下标
8+ Boolean evenIndexOddValue = false ;
9+ Boolean oddIndexEvenValue = false ;
10+
11+ while (i < len -1 && j < len ) {
12+ evenIndexOddValue = isOdd (A [i ]);
13+ oddIndexEvenValue = isEven (A [j ]);
14+
15+ if (!evenIndexOddValue ) i +=2 ;
16+ if (!oddIndexEvenValue ) j +=2 ;
17+ if (evenIndexOddValue && oddIndexEvenValue ) {
18+ int tempVal = A [i ];
19+ A [i ] = A [j ];
20+ A [j ] = tempVal ;
21+
22+ i += 2 ;
23+ j += 2 ;
24+
25+ }
26+ }
27+
28+
29+ return A ;
30+ }
31+
32+ public boolean isEven (int value ) {
33+
34+ return value %2 == 0 ? true : false ;
35+ }
36+
37+ public boolean isOdd (int value ) {
38+
39+ return value %2 == 1 ? true : false ;
40+ }
41+
42+ }
You can’t perform that action at this time.
0 commit comments