The question of Remove Duplicates from Sorted List


  • 2
    L
    public class Solution {
        public ListNode deleteDuplicates(ListNode head) {
            if(head == null)return null;
            ListNode h1 = head;
            int size = 0;
            int count = 0;
            int count_num = 0;
            while(h1 != null){
                size++;
                h1 = h1.next;
            }
            ListNode[] list = new ListNode[size];
            list[0] = head;
            count_num++;
            head = head.next;
            while(count < size - 1){
                    if(list[count_num - 1].val != head.val && head != null){
                        list[count_num] = head;
                        count_num++;
                    }
                count++;
                head = head.next;
            }
            return list[0];
        }
    }
    

    Please tell me why I get wrong answer


Log in to reply
 

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