File tree 4 files changed +63
-0
lines changed 4 files changed +63
-0
lines changed Original file line number Diff line number Diff line change
1
+ // java.util.* and java.util.streams.* have been imported for this problem.
2
+ // You don't need any other imports.
3
+
4
+ public ListNode deleteAtTail (ListNode head ) {
5
+ if (head == null || head .next == null ) return null ;
6
+
7
+ ListNode node = head ;
8
+
9
+ while (node .next .next != null ) {
10
+ node = node .next ;
11
+ }
12
+
13
+ node .next = null ;
14
+ return head ;
15
+ }
Original file line number Diff line number Diff line change
1
+ // java.util.* and java.util.streams.* have been imported for this problem.
2
+ // You don't need any other imports.
3
+
4
+ public ListNode findMiddleNode (ListNode head ) {
5
+ if (head == null || head .next == null ) return head ;
6
+
7
+ ListNode fast = head ;
8
+ ListNode slow = head ;
9
+ while (fast .next != null && fast .next .next != null ) {
10
+ slow = slow .next ;
11
+ fast = fast .next .next ;
12
+ }
13
+
14
+ return slow ;
15
+ }
Original file line number Diff line number Diff line change
1
+ // java.util.* and java.util.streams.* have been imported for this problem.
2
+ // You don't need any other imports.
3
+
4
+ public static void flipHorizontalAxis (int [][] matrix ) {
5
+ int rowLength = matrix .length - 1 ;
6
+
7
+ for (int i = 0 ; i < matrix .length / 2 ; i ++) {
8
+ for (int j = 0 ; j < matrix [i ].length ; j ++) {
9
+ int temp = matrix [i ][j ];
10
+ matrix [i ][j ] = matrix [rowLength - i ][j ];
11
+ matrix [rowLength - i ][j ] = temp ;
12
+ }
13
+ }
14
+ }
Original file line number Diff line number Diff line change
1
+ // java.util.* and java.util.streams.* have been imported for this problem.
2
+ // You don't need any other imports.
3
+
4
+ public static boolean isStringPalindrome (String str ){
5
+ if (str == null || str .length () == 0 ) return true ;
6
+
7
+ int lastIndex = str .length () - 1 ;
8
+
9
+ for (int i = 0 ; i <= lastIndex / 2 ; i ++) {
10
+
11
+ char start = str .charAt (i );
12
+ char end = str .charAt (lastIndex - i );
13
+ if (start != end ) {
14
+ return false ;
15
+ }
16
+ }
17
+
18
+ return true ;
19
+ }
You can’t perform that action at this time.
0 commit comments