码迷,mamicode.com
首页 > 其他好文 > 详细

LeetCode83——Remove Duplicates from Sorted List

时间:2015-02-11 16:44:16      阅读:117      评论:0      收藏:0      [点我收藏+]

标签:c++   leetcode   

Given a sorted linked list, delete all duplicates such that each element appear only once.

For example,

Given 1->1->2, return 1->2.
Given 1->1->2->3->3, return 1->2->3.

难度系数:

容易

实现

ListNode *deleteDuplicates(ListNode *head) {
    ListNode *next = NULL;
    ListNode *curr = head;
    while (curr) {
        if (curr->next == NULL) {
            return head;
        }
        next = curr->next;
        if (curr->val == next->val) {
            curr->next = next->next;
            continue;
        }
        curr = curr->next;
    }
    return head;
}

LeetCode83——Remove Duplicates from Sorted List

标签:c++   leetcode   

原文地址:http://blog.csdn.net/booirror/article/details/43734515

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!