MCPcopy Create free account
hub / github.com/Vishruth-S/CompetitiveCode / Solution

Class Solution

LeetCode_problems/Delete Node/Solution.java:9–23  ·  view source on GitHub ↗

Definition for singly-linked list. public class ListNode { int val; ListNode next; ListNode(int x) { val = x; } }

Source from the content-addressed store, hash-verified

7 * }
8 */
9class Solution {
10 public void deleteNode(ListNode node) {
11 /*There is a trivial way to do this question:by traversing the list from start
12 and checking each node if its the given node to be deleted,if it is then
13 deleting it(we will also need a pointer which points to the previous node)*/
14 /*since in this question we don't have access to head,we can do this by
15 copying the value of next node (node next to the node to be deleted) to node
16 to be deleted and deleting the next node,and making this deleted node point to
17 the node which is two positions ahead*/
18 int a=node.next.val;
19 node.val=a;
20 node.next=node.next.next;
21
22 }
23}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected