We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 35548f1 commit 15f6dc0Copy full SHA for 15f6dc0
Algorithms/Easy/284_PalindromeLinkedList/Solution.py
@@ -0,0 +1,30 @@
1
+class Solution:
2
+ def isPalindrome(self, head: Optional[ListNode]) -> bool:
3
+ fast, slow = head, head
4
+
5
+ while fast != None and fast.next != None:
6
+ fast = fast.next.next
7
+ slow = slow.next
8
9
+ slow = self.reverse(slow)
10
+ fast = head
11
12
+ while slow != None:
13
+ if fast.val != slow.val:
14
+ return False
15
16
+ fast = fast.next
17
18
19
+ return True
20
21
+ def reverse(self, head):
22
+ prev = None
23
24
+ while head != None:
25
+ next = head.next
26
+ head.next = prev
27
+ prev = head
28
+ head = next
29
30
+ return prev
0 commit comments