Skip to content

Commit

Permalink
Delete Node in a Linked List
Browse files Browse the repository at this point in the history
  • Loading branch information
imashiqe committed Oct 26, 2024
1 parent 0947c22 commit bec3e1e
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions datastucture/leetcode/module11/delete_node_linkedlist.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/**
* 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) {
node-> val=node->next->val;
ListNode* deleteNode = node->next;
node->next = node->next->next;
delete deleteNode;
}
};

0 comments on commit bec3e1e

Please sign in to comment.