标签:style blog io color sp for div on log
这次是做题最顺的一次,提交两次,耗时1分钟就ac了,错的那次是因为没有考虑到空链表,少了一个判断。
/** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode(int x) { * val = x; * next = null; * } * } */ public class Solution { public ListNode deleteDuplicates(ListNode head) { if(head==null||head.next==null){ return head; }else{ ListNode pre=head; ListNode cur=head.next; while(cur!=null){ if(cur.val==pre.val){ pre.next=cur.next; }else{ pre=cur; } cur=cur.next; } return head; } } }
Remove Duplicates from Sorted List
标签:style blog io color sp for div on log
原文地址:http://www.cnblogs.com/bluedreamviwer/p/4082656.html