LeetCode Solutions

237. Delete Node in a Linked List

Time: $O(1)$

Space: $O(1)$

			

class Solution {
 public:
  void deleteNode(ListNode* node) {
    node->val = node->next->val;
    node->next = node->next->next;
  }
};
			

class Solution {
  public void deleteNode(ListNode node) {
    node.val = node.next.val;
    node.next = node.next.next;
  }
}
			

class Solution:
  def deleteNode(self, node):
    node.val = node.next.val
    node.next = node.next.next