83. Remove Duplicates from Sorted List
2016-07-03 10:51
288 查看
Given a sorted linked list, delete all duplicates such that each element appear only
once.
For example,
Given
Given
Subscribe to see which companies asked this question
代码:
/**
* 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 * prepare=head;
while(head && head->next)
{
if(head->val == head->next->val)
{
head->next=head->next->next;
}
else
{
head= head->next;
}
}
return prepare;
}
};
once.
For example,
Given
1->1->2, return
1->2.
Given
1->1->2->3->3, return
1->2->3.
Subscribe to see which companies asked this question
代码:
/**
* 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 * prepare=head;
while(head && head->next)
{
if(head->val == head->next->val)
{
head->next=head->next->next;
}
else
{
head= head->next;
}
}
return prepare;
}
};
相关文章推荐
- HDU 1847 Good Luck in CET-4 Everybody!(博弈)
- Error creating the view. An error occurred while automatically activating bundle
- Error creating the view. An error occurred while automatically activating bundle
- hdu 5067 Harry And Dig Machine (TSP类,简单)
- 随记,性能相关
- Java千百问_06数据结构(025)_用二进制如何表示浮点型数值
- 前端之CSS(二)
- 7.3图论模拟
- latex排版论文(1)
- ZooKeeper概述(三)
- bzoj4381: [POI2015]Odwiedziny
- 剑指offer-3-面试13:在O(1)时间删除链表结点
- HDU-5702-Solving Order【2016CCPC女生专场】
- HDU 1846 Brave Game(博弈)
- EntityFramework Code-First 简易教程(十)-------多对多
- 7 款顶级开源 BI(商务智能)软件和报表工具
- caffe 学习系列之finetuning
- git命令cherrypick
- latex(2)排版论文《自动化学报》
- svn-clearup 报错的处理(Cleanup failed to process the following paths...)