Clear Java solution


  • 3
    K
    public class Solution {
        public ListNode deleteDuplicates(ListNode head) {
            if(head == null) return null;
            ListNode pre = head;
            ListNode cur = head.next;
            while(cur != null){
                if(cur.val == pre.val){
                    pre.next = cur.next;
                    cur = cur.next;
                }
                else{
                    pre = pre.next;
                    cur = pre.next;
                }
            }
            return head;
        }
    }

Log in to reply
 

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