# 237. Delete Node in a Linked List

## 1.問題&#x20;

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

![](https://901207480-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LGKoChvN9am4__HCIRK%2F-LYszGH1ddMyMgfmKjUh%2F-LYszO1WMupNeTg4fnQV%2Fimage.png?alt=media\&token=7f6c349a-812e-4352-96c7-6007f1359d99)

## 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;
    }
};
```
