[LeetCode] Remove Duplicates from Sorted List II 链表
2024-08-31 06:01:06
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
控制好便可以了。
#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 ;
}
最新文章
- ConcurrentDictionary线程不安全么,你难道没疑惑,你难道弄懂了么?
- HDU 4745---Two Rabbits(区间DP)
- RGB to HSI, HSI to RGB Conversion Calculator
- 关于Windows Phone平台音乐播放的的技术调研
- Binary Tree Right Side View
- Android标签云控件:TagCloudLinkView
- Golang,用map写个单词统计器
- Java 加密解密 对称加密算法 非对称加密算法 MD5 BASE64 AES RSA
- python的str,unicode对象的encode和decode方法
- 初学Python(五)——元组
- 开启第一个Node.js的Express项目
- Appium移动自动化框架初探
- mysql单表删除记录DELETE
- JBPM工作流(四)——管理流程定义
- Python3 tkinter基础 Canvas delete 删除画布中的所有图形
- C++标准模板库(STL)介绍:string的基本用法
- 001-window版redis安装
- # 20145314《信息安全系统设计基础》期中复习总结 Part B
- 4946: [Noi2017]蔬菜
- Item 8 覆盖equals时请遵守通用约定
热门文章
- ELK详细安装部署
- 用dump为什么总会在前面出现/path/debug.php:193
- HDU:2594-Simpsons’ Hidden Talents
- 笔记-网络-抓包-wireshark
- cogs:1619. [HEOI2012]采花/luogu P2056
- ajax提交表单,支持文件上传
- appium环境搭建(python+windows)
- Python+Selenium练习篇之6-利用class name定位元素
- APM简介
- caffe的python接口提取resnet101某层特征