Can't find errors in my codes, but there are always wrong. Need help!


  • 0
    V
    public class Solution {
    public ListNode deleteDuplicates(ListNode head) {
        if(head!=null&&head.next!=null){
            ListNode p1 = head;
            ListNode p2 = p1.next;
            while(p2!=null){
                if(p1.val==p2.val){
                    while(p2!=null && p1.val==p2.val){
                        p2 = p2.next;
                    }
                if(p1==head){
                    head = p2;
                    }
                }
                p1 = p2;
                if(p2!=null){
                    p2 = p2.next; 
                }
            }
        } 
        return head;
    }
    

    }


  • 0
    V

    I've find my wrong places in my codes. The changes of p1,p2 can't deliver to head.So the output is always the same.


Log in to reply
 

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