JAVA code 1 ms.How to make it better?Anyone


  • 0
    R

    '''
    public class Solution {
    public ListNode deleteDuplicates(ListNode head) {
    if(head == null || head.next == null)return head;
    ListNode temp=head,prev=null;
    while(temp!=null)
    {
    if(prev!=null && prev.val==temp.val)
    {
    prev.next=temp.next;
    temp.next=null;
    }
    else
    prev=temp;
    temp=prev.next;
    }
    return head;
    }
    }
    '''


Log in to reply
 

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