###### Delete Node in a Linked List
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.

/**
* struct ListNode {
*     int val;
*     ListNode *next;
*     ListNode(int x) : val(x), next(NULL) {}
* };
*/
class Solution {
public:
void deleteNode(ListNode* node) {
//给出要删除的节点，可以将其后面的数值复制到前一个节点。这样就可以起到删除给定节点的目的
ListNode *p=node;
ListNode *pre=NULL;
while(p->next)
{
p->val=p->next->val;
pre=p;
p=p->next;
}
pre->next=NULL;
return;
}
};

/**
* 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=tmp->val;
node->next=tmp->next;
delete tmp;
return;
}
};

#### LeetCode 237 : Delete Node in a Linked List

2015-07-27 13:54:09

#### Leetcode_237_Delete Node in a Linked List

2015-08-07 09:53:09

#### [leetcode-237]Delete Node in a Linked List(C语言)

2015-07-17 10:55:15

#### 237. Delete Node in a Linked List [easy] (Python)

2016-05-13 21:18:06

#### leetcode 237: Delete Node in a Linked List

2015-07-15 14:50:40

#### 237. Delete Node in a Linked List（python）

2016-09-18 21:47:47

#### LintCode Delete Node in the Middle of Singly Linked List 在O(1)时间复杂度删除链表节点

2015-07-14 09:33:30

#### LeetCode 237 -Delete Node in a Linked List ( JAVA )

2016-04-06 16:22:58

#### LeetCode-237:Delete Node in a Linked List (Python)

2016-04-09 23:29:06

#### [LeetCode-237] Delete Node in a Linked List（删除链表中节点）

2015-09-04 15:30:31

## 不良信息举报

Delete Node in a Linked List