class Solution(object):
def isPalindrome(self, head):
Si here i make a copy of the head
temp1 = head
temp2 = head
temp3 = head
x = head
if temp1 == None:
return True
else:
temp2 = temp1.next
temp1.next == None
This is where i reverse the listnode
while temp2!= None:
x = temp2.next
temp2.next = temp1
temp1 = temp2
temp2 = x
i=i+1
This is where I compare the original listnode(head) to the reversedlistnode
while head!=None:
print(str(temp1.val)+" "+str(head.val))
if temp1.val != temp2.val:
return False
temp1 = temp1.next
head = head.next
return True
when i try to run this if goes on an infinite loop it is a problem in leetcod(palindrom linked list) however what i want to know is if it alters the original listnode if i make a copy of the head hence the title. Can someone explaint it to me