Merge pull request #2005 from via24/master

修改 0203.移除链表元素.md 写法更Python一点
This commit is contained in:
程序员Carl
2023-04-15 10:45:51 +08:00
committed by GitHub

View File

@ -316,8 +316,8 @@ class Solution:
def removeElements(self, head: ListNode, val: int) -> ListNode: def removeElements(self, head: ListNode, val: int) -> ListNode:
dummy_head = ListNode(next=head) #添加一个虚拟节点 dummy_head = ListNode(next=head) #添加一个虚拟节点
cur = dummy_head cur = dummy_head
while(cur.next!=None): while cur.next:
if(cur.next.val == val): if cur.next.val == val:
cur.next = cur.next.next #删除cur.next节点 cur.next = cur.next.next #删除cur.next节点
else: else:
cur = cur.next cur = cur.next