StackTc 2018-05-29 10:16 采纳率: 90.9%
浏览 607
已采纳

leetcode算法,我写的错的 求指导为什么。

图片说明

图片说明

求解:

  • 写回答

3条回答 默认 最新

  • oyljerry 2018-05-29 10:45
    关注
     /** 
     * Definition for ListNode 
     * public class ListNode { 
     *     int val; 
     *     ListNode next; 
     *     ListNode(int x) { 
     *         val = x; 
     *         next = null; 
     *     } 
     * } 
     */  
    public class Solution {  
        /** 
         * @param ListNode head is the head of the linked list 
         * @return: ListNode head of linked list 
         */  
        public static ListNode deleteDuplicates(ListNode head) {   
            // write your code here  
            if(head==null){  
                return null;  
            }  
            ListNode list=head;  
            while(list.next!=null){  
                if(list.val==list.next.val){  
                    if(list.next.next==null){  
                        list.next=null;  
                    }else{  
                        ListNode node=list.next;  
                        list.next=node.next;  
                    }  
                }else{  
                    list=list.next;  
                }  
            }  
            return head;  
    
        }    
    }  
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?