Java 1ms solution


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

Log in to reply
 

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