237. Delete Node in a Linked List--LeetCode Record
Write a function to delete a node (except the tail) in a singly linked list, given only access to that node.
Supposed the linked list is 1 -> 2 -> 3 -> 4 and you are given the third node with value 3, the linked list should become 1 -> 2 -> 4 after calling your function.
沒有swift選擇,所有就用c++了,語法都忘了。。。
/**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* ListNode *next;
* ListNode(int x) : val(x), next(NULL) {}
* };
*/
class Solution {
public:
void deleteNode(ListNode* node) {
// 向後刪除
if(node->next)
{
node->val=node->next->val;
node->next=node->next->next;
}
else
node=NULL;
}
};
相關文章
- Leetcode 237. Delete Node in a Linked ListLeetCodedelete
- 206. Reverse Linked List--LeetCode RecordLeetCode
- LeetCode Delete Node in a Linked ListLeetCodedelete
- delete duplication record in sql serverdeleteSQLServer
- [CareerCup] 2.3 Delete Node in a Linked List 刪除連結串列的節點delete
- 每天一道LeetCode--237.Delete Node in a Linked ListLeetCodedelete
- 450-Delete Node in a BSTdelete
- LeetCode 382 Linked List Random NodeLeetCoderandom
- LeetCode-Linked List Random NodeLeetCoderandom
- react-recordReact
- Daily record-SeptemberAI
- delete input 與 delete all inputdelete
- delete OBSOLETE 與 delete expirieddelete
- deletedelete
- delete 和 delete [] 的真正區別delete
- 實戰 Java 16 值型別 Record - 2. Record 的基本用法Java型別
- pl/sql record 詳解SQL
- delete與delete[]需要注意的地方delete
- FormData delete()ORMdelete
- URLSearchParams delete()delete
- JavaScript deleteJavaScriptdelete
- DELETE STATISTICSdelete
- rman 中delete 與delete force 的區別delete
- Java 16 新特性:record類Java
- Erlang中的Record詳解
- 淺析 record 使用場景
- Record It for Mac錄屏軟體Mac
- Java 21 新特性:Record PatternsJava
- 脫離rails 使用Active RecordAI
- Homework record-Simple sorting
- gorm忽略報錯: record not foundGoORM
- leetcode Linked List CycleLeetCode
- 92. Reverse Linked List II
- MySQL Delete PHPMySqldeletePHP
- WeakMap delete() 方法delete
- WeakSet delete() 方法delete
- Map delete() 方法delete
- SQL__DELETESQLdelete