5 line - 1ms - Java solution


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

Log in to reply
 

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