#-*- coding: UTF-8 -*-
# Definition for singly-linked list.
# class ListNode(object):
# def __init__(self, x):
# self.val = x
# self.next = None
class Solution(object):
def removeElements(self, head, val):
"""
:type head: ListNode
:type val: int
:rtype: ListNode
"""
if head==None:return []
dummy=ListNode(-1)
dummy.next=head
p=dummy
while head:
if head.val==val:
p.next=head.next
head=p
p=head
head=head.next
return dummy.next
相关文章
- Remove Linked List Elements
- 【LeetCode】237. Delete Node in a Linked List 解题报告 (Java&Python&C++)
- LeeCode-Remove Linked List Elements
- [leetcode]Reverse Linked List II @ Python
- Leetcode 203 Remove Linked List Elements 链表
- [LeetCode]题解(python):019-Remove Nth Node From End of List
- [LeetCode] Remove Linked List Elements
- LeetCode[Linked List]: Remove Duplicates from Sorted List II
- [LeetCode] Remove Linked List Elements 移除链表元素
- [LintCode] Remove Linked List Elements 移除链表元素