Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numbers from the original list.

For example,
Given 1->2->3->3->4->4->5, return 1->2->5.
Given 1->1->1->2->3, return 2->3.

Hide Tags

Linked List

 

  控制好便可以了。
#include <iostream>
using namespace std; /**
* 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 ret();
ListNode * pslow=&ret,*pfast=head;
while(){
if(pfast==NULL) break;
bool dup = false;
int curVal = pfast->val;
pfast=pfast->next;
while(pfast!=NULL&&pfast->val==curVal){
dup = true;
pfast=pfast->next;
}
if(dup==false){
pslow->next = new ListNode(curVal);
pslow=pslow->next;
}
}
return ret.next;
}
}; int main()
{
return ;
}

最新文章

  1. ConcurrentDictionary线程不安全么,你难道没疑惑,你难道弄懂了么?
  2. HDU 4745---Two Rabbits(区间DP)
  3. RGB to HSI, HSI to RGB Conversion Calculator
  4. 关于Windows Phone平台音乐播放的的技术调研
  5. Binary Tree Right Side View
  6. Android标签云控件:TagCloudLinkView
  7. Golang,用map写个单词统计器
  8. Java 加密解密 对称加密算法 非对称加密算法 MD5 BASE64 AES RSA
  9. python的str,unicode对象的encode和decode方法
  10. 初学Python(五)——元组
  11. 开启第一个Node.js的Express项目
  12. Appium移动自动化框架初探
  13. mysql单表删除记录DELETE
  14. JBPM工作流(四)——管理流程定义
  15. Python3 tkinter基础 Canvas delete 删除画布中的所有图形
  16. C++标准模板库(STL)介绍:string的基本用法
  17. 001-window版redis安装
  18. # 20145314《信息安全系统设计基础》期中复习总结 Part B
  19. 4946: [Noi2017]蔬菜
  20. Item 8 覆盖equals时请遵守通用约定

热门文章

  1. ELK详细安装部署
  2. 用dump为什么总会在前面出现/path/debug.php:193
  3. HDU:2594-Simpsons’ Hidden Talents
  4. 笔记-网络-抓包-wireshark
  5. cogs:1619. [HEOI2012]采花/luogu P2056
  6. ajax提交表单,支持文件上传
  7. appium环境搭建(python+windows)
  8. Python+Selenium练习篇之6-利用class name定位元素
  9. APM简介
  10. caffe的python接口提取resnet101某层特征