My Java solution.


  • 3
    A
    public class Solution {
        public void deleteNode(ListNode node) {
            ListNode nxtNode=node.next;
            node.val=nxtNode.val;
            node.next=nxtNode.next;
            
        }
    }
    

    I think my solution is a little better than the official solution


  • 1
    J

    Its the same. all you do is create a reference to the next node. I feel it is less readable and wastes a line.


Log in to reply
 

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