File tree Expand file tree Collapse file tree 1 file changed +6
-13
lines changed
src/main/java/com/fishercoder/solutions Expand file tree Collapse file tree 1 file changed +6
-13
lines changed Original file line number Diff line number Diff line change 5
5
import java .util .ArrayList ;
6
6
import java .util .List ;
7
7
8
- /**
9
- * 234. Palindrome Linked List
10
- *
11
- * Given a singly linked list, determine if it is a palindrome.
12
-
13
- Follow up:
14
- Could you do it in O(n) time and O(1) space?
15
- */
16
-
17
8
public class _234 {
18
9
public static class Solution1 {
19
- /**O(n) time
10
+ /**
11
+ * O(n) time
20
12
* O(1) space
21
- * * /
13
+ */
22
14
public boolean isPalindrome (ListNode head ) {
23
15
if (head == null ) {
24
16
return true ;
@@ -56,9 +48,10 @@ private ListNode reverse(ListNode head) {
56
48
}
57
49
58
50
public static class Solution2 {
59
- /**O(n) time
51
+ /**
52
+ * O(n) time
60
53
* O(n) space
61
- * * /
54
+ */
62
55
public boolean isPalindrome (ListNode head ) {
63
56
int len = 0 ;
64
57
ListNode fast = head ;
You can’t perform that action at this time.
0 commit comments