From 7c6930971d6175fe6656a4b31c4ac1c6d765d795 Mon Sep 17 00:00:00 2001 From: Eyjan_Huang <81480748+Eyjan-Huang@users.noreply.github.com> Date: Thu, 19 Aug 2021 15:00:28 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=200203.=E7=A7=BB=E9=99=A4?= =?UTF-8?q?=E9=93=BE=E8=A1=A8=E5=85=83=E7=B4=A0.md=20python=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 使用更符合PEP8要求的代码规范来约束 --- problems/0203.移除链表元素.md | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/problems/0203.移除链表元素.md b/problems/0203.移除链表元素.md index f3724fc2..d67a7d2a 100644 --- a/problems/0203.移除链表元素.md +++ b/problems/0203.移除链表元素.md @@ -245,13 +245,15 @@ Python: # def __init__(self, val=0, next=None): # self.val = val # self.next = next + class Solution: def removeElements(self, head: ListNode, val: int) -> ListNode: - dummy_head = ListNode(next=head) #添加一个虚拟节点 + dummy_head = ListNode(next=head) cur = dummy_head - while(cur.next!=None): - if(cur.next.val == val): - cur.next = cur.next.next #删除cur.next节点 + + while cur.next: + if cur.next.val == val: + cur.next = cur.next.next # 删除下一个节点 else: cur = cur.next return dummy_head.next