-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path234.py
More file actions
37 lines (32 loc) · 745 Bytes
/
234.py
File metadata and controls
37 lines (32 loc) · 745 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# Definition for singly-linked list.
from copy import deepcopy
class ListNode(object):
def __init__(self, x):
self.val = x
self.next = None
class Solution(object):
def isPalindrome(self, head):
"""
:type head: ListNode
:rtype: bool
"""
if head==None: return True
p = head
l = []
while p:
l.append(p.val)
p = p.next
lr = deepcopy(l)
lr.reverse()
return l==lr
def createNode(self):
head = ListNode(0)
nums = [1,2,1]
for x in nums:
p = ListNode(x)
p.next = head.next
head.next = p
return head.next
test = Solution()
head = test.createNode()
print test.isPalindrome(head)