Java simple solution


  • 0
    M

    You can pass a LinkedList of any size for this function, not only 1->2->3->4->5

    public class Solution {
        
        public void deleteNode(ListNode node) {
            
            ListNode n = node;
            while (n != null) {
                n.val = n.next.val;
                if (n.next.next == null) {
                    n.next = null;
                    break;
                }
                n = n.next;
            }
            
        }
        
    }
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.