LeetCode:83.Remove Duplicates from Sorted List
来源:互联网 发布:大亚湾网络问政 编辑:程序博客网 时间:2024/06/05 14:16
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
.
C++ Solution:
/**
* 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* current = head;
ListNode* p;
while(current!=NULL && current->next != NULL) {
if (current->val == current->next->val) {
p = current->next;
current->next = p->next;
free(p);
}
else {
current= current->next;
}
}
return head;
}
};
- [LeetCode]83.Remove Duplicates from Sorted List
- [Leetcode] 83. Remove Duplicates from Sorted List
- LeetCode --- 83. Remove Duplicates from Sorted List
- [leetcode] 83.Remove Duplicates from Sorted List
- LeetCode 83. Remove Duplicates from Sorted List
- 【leetcode】83. Remove Duplicates from Sorted List
- 83. Remove Duplicates from Sorted List LeetCode
- leetcode 83. Remove Duplicates from Sorted List
- [LeetCode]83. Remove Duplicates from Sorted List
- 【LeetCode】83. Remove Duplicates from Sorted List
- LeetCode 83. Remove Duplicates from Sorted List
- [leetcode] 83. Remove Duplicates from Sorted List
- leetcode 83. Remove Duplicates from Sorted List
- LeetCode *** 83. Remove Duplicates from Sorted List
- LeetCode - 83. Remove Duplicates from Sorted List
- 【LeetCode】83. Remove Duplicates from Sorted List
- LeetCode 83. Remove Duplicates from Sorted List
- [LeetCode]83. Remove Duplicates from Sorted List
- logistics笔记
- ACM博弈论总结
- 论文翻译(1)FaceNet: A Unified Embedding for Face Recognition and Clustering
- IO流(一)和深入递归
- Web Angular用户密码强度判别
- LeetCode:83.Remove Duplicates from Sorted List
- python爬虫框架scrapy实例详解
- codeforces864F Cities Excursions 图论,tarjan算法的应用
- Java多线程学习(吐血超详细总结)
- FPGA在其他领域的应用(二)
- 快速搭建ssh框架--ideamac版
- 构造方法传参数
- 软件测试(一)
- 深入浅出朴素贝叶斯法(Naive Bayes)