leetcode刷題--Remove Linked List Elements
題目:刪除連表中值為給定值的元素
這道題沒啥好說的,先自己定義一個啞節點,啞節點將指向要返回的頭結點
class Solution:
# @param {ListNode} head
# @param {integer} val
# @return {ListNode}
def removeElements(self, head, val):
dummy = ListNode(0)
dummy.next = head
node = dummy
while node and node.next:
if node.next.val == val:
node.next = node.next.next
else:
node = node.next
return dummy.next
相關文章
- LeetCode | 203. Remove Linked List ElementsLeetCodeREM
- Leetcode 203. Remove Linked List ElementsLeetCodeREM
- leetcode刷題--Reverse Linked ListLeetCode
- [LeetCode] 2487. Remove Nodes From Linked ListLeetCodeREM
- leetcode Linked List CycleLeetCode
- Leetcode Reverse Linked List IILeetCode
- Leetcode Linked List Cycle IILeetCode
- LeetCode Delete Node in a Linked ListLeetCodedelete
- Leetcode Palindrome Linked ListLeetCode
- LeetCode 83.Remove Duplicates from Sorted List(從已排序連結串列中除去重複) Easy/Linked ListLeetCodeREM排序
- Leetcode Remove Duplicates from Sorted ListLeetCodeREM
- [leetcode]linked-list-cycle-iiLeetCode
- LeetCode 382 Linked List Random NodeLeetCoderandom
- LeetCode-Palindrome Linked ListLeetCode
- LeetCode-Linked List Random NodeLeetCoderandom
- LeetCode-Odd Even Linked ListLeetCode
- Leetcode-Reverse Linked List IILeetCode
- Leetcode-Linked List Cycle IILeetCode
- Reverse Linked List II leetcode javaLeetCodeJava
- LeetCode | 141 linked list cycleLeetCode
- Leetcode Remove Duplicates from Sorted List IILeetCodeREM
- Leetcode Remove Nth Node From End of ListLeetCodeREM
- Leetcode-Remove Duplicates from Sorted ListLeetCodeREM
- Remove Duplicates from Sorted List leetcode javaREMLeetCodeJava
- [LeetCode] 328. Odd Even Linked ListLeetCode
- 【Leetcode】141. Linked List CycleLeetCode
- LeetCode141:Linked List CycleLeetCode
- 【LeetCode】Flatten Binary Tree to Linked ListLeetCode
- Leetcode Flatten Binary Tree to Linked ListLeetCode
- leetcode141: Linked List CycleLeetCode
- Leetcode 19 Remove Nth Node From End of ListLeetCodeREM
- LeetCode 83. Remove Duplicates from Sorted ListLeetCodeREM
- 【Leetcode】83. Remove Duplicates from Sorted ListLeetCodeREM
- Leetcode-Remove Duplicates from Sorted List IILeetCodeREM
- Leetcode-Remove Nth Node From End of ListLeetCodeREM
- Remove Duplicates from Sorted List II leetcode javaREMLeetCodeJava
- Remove Nth Node From End of List leetcode javaREMLeetCodeJava
- LeetCode之Odd Even Linked List(Kotlin)LeetCodeKotlin