[leetcode]Remove Duplicates from Sorted List

简单题。

public class Solution {
    public ListNode deleteDuplicates(ListNode head) {
        if (head == null) return null;
        if (head.next == null) return head;
        ListNode last = head;
        ListNode current = head.next;
        while (current != null)
        {
            if (last.val == current.val)
            {
                last.next = current.next;
                current = last.next;
            }
            else
            {
                last = current;
                current = last.next;
            }
        }
        return head;
    }
}

  

posted @ 2013-09-17 21:51  阿牧遥  阅读(137)  评论(0编辑  收藏  举报