[LeetCode] Remove Duplicates from Sorted List II 链表
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
.
控制好便可以了。
#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 ;
}
[LeetCode] Remove Duplicates from Sorted List II 链表的更多相关文章
- Leetcode: Remove Duplicates from Sorted List II 解题报告
Remove Duplicates from Sorted List II Given a sorted linked list, delete all nodes that have duplica ...
- [LeetCode] Remove Duplicates from Sorted List II 移除有序链表中的重复项之二
Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numb ...
- [LeetCode] Remove Duplicates from Sorted Array II 有序数组中去除重复项之二
Follow up for "Remove Duplicates":What if duplicates are allowed at most twice? For exampl ...
- [Leetcode] Remove Duplicates From Sorted Array II (C++)
题目: Follow up for "Remove Duplicates":What if duplicates are allowed at most twice? For ex ...
- [Leetcode] Remove duplicates from sorted array ii 从已排序的数组中删除重复元素
Follow up for "Remove Duplicates":What if duplicates are allowed at most twice? For exampl ...
- [LeetCode] Remove Duplicates from Sorted Array II [27]
题目 Follow up for "Remove Duplicates": What if duplicates are allowed at most twice? For ex ...
- [leetcode]Remove Duplicates from Sorted Array II @ Python
原题地址:https://oj.leetcode.com/problems/remove-duplicates-from-sorted-array-ii/ 题意: Follow up for &quo ...
- [LeetCode] Remove Duplicates from Sorted List II
Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numb ...
- [leetcode]Remove Duplicates from Sorted List II @ Python
原题地址:https://oj.leetcode.com/problems/remove-duplicates-from-sorted-list-ii/ 题意: Given a sorted link ...
随机推荐
- vim正则表达式的替换变量
在正规表达式中使用 \( 和 \) 符号括起正规表达式,即可在后面使用\1.\2 等变量来访问 \( 和 \) 中的内容. 例如有下列英汉对照文本: adapter 适配器address 地址alge ...
- pymysql模块操作数据库及连接报错解决方法
import pymysql sql = "select host,user,password from user" #想要执行的MySQL语句 #sql = 'create da ...
- GNU汇编 函数调用的例子
.text .global _start _start: mov r1,#2 cmp r1,#1 bl func1 @bl能保存下一条指令的位置到lr寄存器里面,b不能 mov r1, # ...
- 809. Expressive Words
https://leetcode.com/problems/expressive-words/description/ class Solution { public: int expressiveW ...
- Gender Equality in the Workplace【职场上的性别平等】
Gender Equality in the Workplace A new batch of young women - members of the so-called Millennial ge ...
- git初次建立远程仓库问题
git "Could not read from remote repository.Please make sure you have the correct access rights. ...
- 【SHELL】Linux下安装Oracle Client
一.新建Oracle脚本存储目录并上传文件 [root@A04-Test-172]# mkdir -p /tmp/instance_oracle #新建存储目录 [root@A04-Test-172 ...
- mybatis是如何防止sql注入?
sql注入发生的时间,sql注入发生的阶段在sql预编译阶段,当编译完成的sql不会产生sql注入 采用jdbc操作数据时候 String sql = "update ft_proposal ...
- 谈一谈Tomcat中webSocket,Jetty WebSocket 和Spring WebSocket以及github中Java-WebSocket.jar分别对Socket协议的角色定位以及效果的不同点;
开局先上一张图:(http://tomcat.apache.org/tomcat-7.0-doc/web-socket-howto.html) 当前截图来自于apache的tomcat官网(问:为 ...
- 在IE浏览器下,PDF将弹出窗口遮挡了
写了个embed标签里面放这个pdf 然后点击其他地方的弹框pdf把他遮盖住了 如下: 先是改z-index,没卵用. 百度了好久,终于找到了个有用的 https://blog.csdn.net/it ...