Why "if head is not None" is wrong? When input [1,2], my code return True.


  • 0
    J

    class Solution(object):
    def isPalindrome(self, head):
    """
    :type head: ListNode
    :rtype: bool
    """
    if not head: return True
    a=[]
    if head is not None:
    a.append(head.val)
    head=head.next

        return a[::1]==a[::-1]

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.