Java Solution 1ms runtime


  • 0
    public class Solution {
        public ListNode deleteDuplicates(ListNode head) {
            if(head==null){
                return null;
            }
            ListNode temp = head;
            ListNode headptr=head;
            ListNode runner=head;
            while(runner!=null){
                if(headptr.val==runner.val){
                    runner=runner.next;
                }
                else{
                    headptr.next=runner;
                    headptr=runner;
                }
            }
            headptr.next=runner;
            return temp;
        }
    }

Log in to reply
 

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