share my java solution!


  • 0
    C
    public class Solution {
        public ListNode deleteDuplicates(ListNode head) {
            if(head==null) return head;
            ListNode current=head;
            ListNode nextnode=head.next;
            while(nextnode!=null){
                if(current.val==nextnode.val){
                    current.next=nextnode.next;
                    nextnode=nextnode.next;
                }else{
                    current=current.next;
                    nextnode=nextnode.next;
                }
            }
            return head;
        }
    }
    
    

Log in to reply
 

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