1 parent d4c73e5 commit 5b42185Copy full SHA for 5b42185
1 file changed
Delete Node in a Linked List
@@ -0,0 +1,24 @@
1
+/**
2
+ * Definition for singly-linked list.
3
+ * struct ListNode {
4
+ * int val;
5
+ * ListNode *next;
6
+ * ListNode(int x) : val(x), next(NULL) {}
7
+ * };
8
+ */
9
+class Solution {
10
+public:
11
+ void deleteNode(ListNode* node)
12
+ {
13
+ ListNode* prev;
14
+ while(node->next!=NULL)
15
16
+ prev=node;
17
+ node = node->next;
18
+ prev->val = node->val;
19
+ }
20
+ prev->next = NULL;
21
+
22
23
24
+};
0 commit comments