Leetcode 237. Delete Node in a Linked List
方法1: 這題目被踩的很厲害,但是對於我來說還是學到點東西的。這題我讓我知道了要徹底刪除一個節點需要知道頭節點,lc給出的做法其實就是修改這個node的值,修改這個node的去向。其實就是把要刪除的node易容成了它的下一個節點,但是本身並沒有刪除。時間1,空間1.
/**
* Definition for singly-linked list.
* public class ListNode {
* int val;
* ListNode next;
* ListNode(int x) { val = x; }
* }
*/
class Solution {
public void deleteNode(ListNode node) {
node.val = node.next.val;
node.next = node.next.next;
}
}
總結:
- 無
相關文章
- 237. Delete Node in a Linked List--LeetCode RecorddeleteLeetCode
- LeetCode Delete Node in a Linked ListLeetCodedelete
- LeetCode 382 Linked List Random NodeLeetCoderandom
- LeetCode-Linked List Random NodeLeetCoderandom
- 每天一道LeetCode--237.Delete Node in a Linked ListLeetCodedelete
- [CareerCup] 2.3 Delete Node in a Linked List 刪除連結串列的節點delete
- leetcode Linked List CycleLeetCode
- Leetcode Reverse Linked List IILeetCode
- Leetcode Linked List Cycle IILeetCode
- Leetcode Palindrome Linked ListLeetCode
- [leetcode]linked-list-cycle-iiLeetCode
- LeetCode-Palindrome Linked ListLeetCode
- LeetCode-Odd Even Linked ListLeetCode
- Leetcode-Reverse Linked List IILeetCode
- Leetcode-Linked List Cycle IILeetCode
- leetcode刷題--Reverse Linked ListLeetCode
- Reverse Linked List II leetcode javaLeetCodeJava
- LeetCode | 141 linked list cycleLeetCode
- [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
- leetcode刷題--Remove Linked List ElementsLeetCodeREM
- leetcode141: Linked List CycleLeetCode
- LeetCode之Odd Even Linked List(Kotlin)LeetCodeKotlin
- Leetcode 142. Linked List Cycle IILeetCode
- LeetCode | 203. Remove Linked List ElementsLeetCodeREM
- Leetcode 234. Palindrome Linked ListLeetCode
- Leetcode 203. Remove Linked List ElementsLeetCodeREM
- 【Leetcode】142.Linked List Cycle IILeetCode
- LeetCode142:Linked List Cycle IILeetCode
- Leetcode-Flatten Binary Tree to Linked ListLeetCode
- Flatten Binary Tree to Linked List leetcode javaLeetCodeJava
- [LeetCode] 2487. Remove Nodes From Linked ListLeetCodeREM
- Leetcode 206. Reverse Linked ListLeetCode
- [LeetCode] 430. Flatten a Multilevel Doubly Linked ListLeetCode
- LeetCode - Easy - 206. Reverse Linked ListLeetCode