2 pointer JAVA


  • 0
    D

    public class Solution {
    public ListNode deleteDuplicates(ListNode head) {

        if(head==null) return null;
        
        
        ListNode h1=head;
        ListNode curr= head;
        while(h1.next!=null)
        {
            
            if(curr.next!=null){
                curr=curr.next;
            if(h1.val==curr.val)
            {
                h1.next=curr.next;
              
            }
            else
            {
                h1=h1.next;
            }
            
           
        }
        }
         return head;
        
    }
    

    }


Log in to reply
 

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