Simple Java solution


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

Log in to reply
 

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