6.4 Linked List 重做

PriorityQueue<ListNode> queue= new PriorityQueue<ListNode>(lists.length,new Comparator<ListNode>(){
            @Override
            public int compare(ListNode o1,ListNode o2){
                if (o1.val<o2.val)
                    return -1;
                else if (o1.val==o2.val)
                    return 0;
                else 
                    return 1;
            }
        });
        
    

错误:
1.不知道如何对PriorityQueue进行声明操作
2.没有在向queue中添加元素之前进行check null的操作

错误:

  1. 接尾巴的时候不知道逻辑,应当声明 p1 = head.next;

    ListNode prev = head;
    ListNode p1 = head.next;
    ListNode curr = p1;
  2. 没有使用 while loop 循环来对整个链表进行操作
  3. check 空指针是对于head.next 来进行check if(next.next == null) return next;

猜你喜欢

转载自www.cnblogs.com/kong-xy/p/9132467.html
今日推荐