Definition for singly-linked list. public class ListNode { int val; ListNode next; ListNode(int x) { val = x; } }
| 7 | * } |
| 8 | */ |
| 9 | class 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 | } |
nothing calls this directly
no outgoing calls
no test coverage detected