Java Solution with variable replacement


  • 0
    E
    /**
     * Definition for singly-linked list.
     * public class ListNode {
     *     int val;
     *     ListNode next;
     *     ListNode(int x) { val = x; }
     * }
     */
    public class Solution {
        public void deleteNode(ListNode node) {
             while(node.next!=null){
                node.val=node.next.val;
                if(node.next.next==null){
                    break;
                }
                node=node.next;
            }
            node.next=null;
        }
    }
    

Log in to reply
 

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