> For the complete documentation index, see [llms.txt](https://jenhsuan.gitbook.io/algorithm/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://jenhsuan.gitbook.io/algorithm/leetcode/237.-delete-node-in-a-linked-list.md).

# 237. Delete Node in a Linked List

## 1.問題&#x20;

* 只給想要刪除的node, 刪掉此node

![](/files/-LYszO1WMupNeTg4fnQV)

## 2.想法&#x20;

* 將此node的值改為此node的下一個node的值, 並刪除下一個node

## 3.程式碼&#x20;

```
/**
 * 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) {
        ListNode* tmp = node->next;
        node->val = node->next->val;
        node->next = node->next->next;
        delete tmp;
    }
};
```
