leetcode83-Remove Duplicates from Sorted List

Posted 鹅要长大

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了leetcode83-Remove Duplicates from Sorted List相关的知识,希望对你有一定的参考价值。

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;

以上是关于leetcode83-Remove Duplicates from Sorted List的主要内容,如果未能解决你的问题,请参考以下文章

leetcode83-Remove Duplicates from Sorted List

[LeetCode] 83. Remove Duplicates from Sorted List

LeetCode83 Remove Duplicates from Sorted List

LeetCode 83 Remove Duplicates from Sorted List

LeetCode:83.Remove Duplicates from Sorted List

leetcode83 Remove Duplicates from Sorted List