April 1 Palindrom linkedlist with python simple
Anonymous User
74
# Definition for singly-linked list.
# class ListNode:
#     def __init__(self, val=0, next=None):
#         self.val = val
#         self.next = next
class Solution:
    def isPalindrome(self, head: ListNode) -> bool:
        lis=[]
        temp=head
        while temp:
            lis.append(temp.val)
            temp=temp.next
        def isPalindrome(s):
	        return s == s[::-1]

        s =""
        for i in lis:
            s=s+str(i)
        

        if isPalindrome(s):
	        return True
        else:
	        return False
Comments (1)