JAVA-----------Easy Version To UnderStand!!!!!!!!!!!!!!


  • 0
    H
        public ListNode deleteDuplicates(ListNode head) {
    	if (head == null || head.next == null)
    		return head;
    	ListNode p = head, q = head.next;
    	p.next = null;
    	while (q != null) {
    		if (q.val == p.val){
    			q = q.next;
    			continue;
    		}
    		else {
    			p.next = q;
    			p = p.next;
    			q = q.next;
    		}
    	}
    	p.next = null;
    	return head;
    }

Log in to reply
 

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