I don't know why my Python solution cannot pass the extra long test case


  • 0
    R

    Here is my solution:

    class Solution(object):
        def removeElements(self, head, val):
            """
            :type head: ListNode
            :type val: int
            :rtype: ListNode
            """
            if head is None:
                return None
            else:
                if head.val != val:
                    head.next = self.removeElements(head.next, val)
                else:
                    head = self.removeElements(head.next,val)
            return head
    

    It works with the [1,2,6,3,4,6],6 test case, but meet Runtime Error with the test case:
    [1,9,9,9,9,9,9,9,...],1. Could anyone help me with it? Thanks a million!


Log in to reply
 

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