237. Delete Node in a Linked List
C++
1class Solution { 2 public: 3 void deleteNode(ListNode* node) { 4 node->val = node->next->val; 5 ListNode *temp = node->next; 6 node->next = node->next->next; 7 delete temp; 8 } 9};
JavaScript
1var deleteNode = function(node) { 2 node.val = node.next.val; 3 node.next = node.next.next; 4};
Ruby
1def delete_node(node) 2 node.val = node.next.val 3 node.next = node.next.next 4end