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

【leetcode】83-Remove Duplicates from Sorted List

时间:2018-11-25 17:48:18      阅读:210      评论:0      收藏:0      [点我收藏+]

标签:pre   ems   return   用法   for   基本   div   solution   span   

problem

Remove Duplicates from Sorted List

考察的是链表的基本用法。

code

/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     ListNode *next;
 *     ListNode(int x) : val(x), next(NULL) {}
 * };
 */
class Solution {
public:
    ListNode* deleteDuplicates(ListNode* head) {
        ListNode* cur = head;
        while(cur && cur->next)//null is error.
        {
            if(cur->val == cur->next->val) cur->next = cur->next->next;
            else cur = cur->next;   //        
        }
        return head;
    }
};

 

 

参考

1. Remove Duplicates from Sorted List;

【leetcode】83-Remove Duplicates from Sorted List

标签:pre   ems   return   用法   for   基本   div   solution   span   

原文地址:https://www.cnblogs.com/happyamyhope/p/10016100.html

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