Leetcode Problem.83—Remove Duplicates from Sorted List
2015-06-03 15:23
211 查看
Given a sorted linked list, delete all duplicates such that each element appear only once.
For example,
Given
Given
My C++ solution!
For example,
Given
1->1->2, return
1->2.
Given
1->1->2->3->3, return
1->2->3.
My C++ solution!
/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */
ListNode* deleteDuplicates(ListNode* head) { vector<int> temp; if(head==NULL) return head; ListNode *p=head; ListNode *q; temp.push_back(p->val); while(p->next) { if(find(temp.begin(),temp.end(),p->next->val)!=temp.end()) { q =p->next->next; p->next=q; } else { temp.push_back(p->next->val); p=p->next; } } return head; }
相关文章推荐
- ueditor富文本
- C++中const、volatile、mutable的用法
- 基于DRBD实现高可用MariaDB
- Centos6.6上rsyslog一些用法和扩展
- Some paper related to Image Deblurring
- switch语句中得case
- linux centos6.5安装KVM
- RDIFramework.NET ━ .NET快速信息化系统开发框架钜献 V2.9 版本震撼发布
- 异常日志以及非异常日志记录方法
- bzoj 1336 最小圆覆盖
- 使用pt-online-schema-change 修复主从数据表数据不一致
- C语言字节对齐
- Leetcode Problem.67—Add Binary
- Leetcode Problem.66—Plus One
- 【HDU】5247-找连续数(直接暴力)
- 如何远程运行PowerShell命令?
- oracle 监测数据库是否存在指定字段
- iOS 真机文件系统区分大小写,而模拟器可能不区分
- java-零散知识点
- samba 最新漏洞代码POC