Skip to content

Commit 3866353

Browse files
hj.tianhj.tian
authored andcommitted
fix: leetcode75 code format
fix: leetcode75 code format
1 parent e7a28ba commit 3866353

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

leetcode75/day18_19.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,19 @@
66
class Solution:
77
def removeNthFromEnd(self, head: Optional[ListNode], n: int) -> Optional[ListNode]:
88
fast, slow, pre = head, head, head
9-
while n > 0:
9+
while n > 0 and fast:
1010
fast = fast.next
1111
n -= 1
12-
while fast:
12+
while fast and slow:
1313
fast = fast.next
1414
pre = slow
1515
slow = slow.next
16-
if pre == slow:
16+
if pre and slow and pre == slow:
1717
head = slow.next
1818
slow.next = None
19-
pre.next = slow.next
20-
slow.next = None
19+
if pre and slow:
20+
pre.next = slow.next
21+
slow.next = None
2122
return head
2223

2324

0 commit comments

Comments
 (0)