0605每日一题203移除链表元素

0605每日一题203移除链表元素

#递归方式
# Definition for singly-linked list.
# class ListNode:
#     def __init__(self, val=0, next=None):
#         self.val = val
#         self.next = next
class Solution:
    def removeElements(self, head: ListNode, val: int) -> ListNode:
        if head is None:
           return head
        head.next = self.removeElements(head.next,val)
        if head.val == val:
            return head.next
        else:
            return head

 

上一篇:203. 移除链表元素


下一篇:203. 移除链表元素