Home [Medium] Delete Node in a Linked List
Post
Cancel

[Medium] Delete Node in a Linked List

‘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;
    }
}
This post is licensed under CC BY 4.0 by the author.

[Medium] Rotate List

[Medium] Maximum Twin Sum of a Linked List

Comments powered by Disqus.