Leetcode学习(15)—— Remove Linked List Elements

xiaoxiao2021-02-28  109

Remove all elements from a linked list of integers that have value val.

Example Given: 1 --> 2 --> 6 --> 3 --> 4 --> 5 --> 6, val = 6 Return: 1 --> 2 --> 3 --> 4 --> 5 class Solution(object): def removeElements(self, head, val): head, head.next = ListNode(None), head p = head while p.next: if p.next.val == val: p.next = p.next.next else: p = p.next return head.next

转载请注明原文地址: https://www.6miu.com/read-55449.html

最新回复(0)