‘Delete Node in a Linked List (Medium)`
📌 Problem
https://leetcode.com/problems/delete-node-in-a-linked-list/
📌 Answer
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
/**
* Definition for singly-linked list.
* public class ListNode {
* int val;
* ListNode next;
* ListNode(int x) { val = x; }
* }
*/
class Solution {
// input node will be deleted node
public void deleteNode(ListNode node) {
ListNode nextNode = node.next;
node.val = nextNode.val;
node.next = nextNode.next;
nextNode.next = null;
}
}
Comments powered by Disqus.