I wanted to solve the palindrome linked list problem.
I went through the linked list, but I don't know how to refer to it in a different function. Here's my code (not working):
def __init__ (self):
self.head = None
def add_end(self, data):
newNode = Node(data)
n = self.head
if self.head is None:
self.head= newNode
n = self.head
while n:
n = n.ref
return self.head
def palindrom(self):
fast = self.head
slow = self.head
while fast and fast.ref:
fast = fast.next.ref
slow = slow.ref
#reserve second half
prev = None
while slow:
tmp = slow.ref
slow.ref = prev
prev =slow
slow = tmp
Could you please help me solve the problem?