<LeetCode OJ> 83. Remove Duplicates from Sorted List
83. Remove Duplicates from Sorted List
Submissions: 264227 Difficulty: Easy
题目意思:如今有一个已经排好顺序的链表,删除全部反复的节点。使每一个节点都仅仅出现一次!
Given a sorted linked list, delete all duplicates such that each element appear only once.
For example,
Given 1->1->2, return 1->2.
Given 1->1->2->3->3, return 1->2->3.
分析:
遍历链表。遍历过程中保存上一个节点的值假设与当前节点同样就删除
维护两个指针。一个指向前一个节点。一个指向当前节点,同样就运行删除操作
/**
* 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) {
if(head==NULL)
return NULL;
ListNode* preNode=head;
ListNode* curNode=head->next;
ListNode* delNode=NULL;
while(curNode)
{
if(preNode->val==curNode->val)
{
preNode->next=curNode->next;
delNode=curNode;
curNode=curNode->next;
delete delNode;
delNode=NULL;
continue;
}
preNode=curNode;
curNode=curNode->next;
} return head;
}
};
注:本博文为EbowTang原创。兴许可能继续更新本文。
假设转载,请务必复制本条信息。
原文地址:http://blog.csdn.net/ebowtang/article/details/50483226
原作者博客:http://blog.csdn.net/ebowtang
<LeetCode OJ> 83. Remove Duplicates from Sorted List的更多相关文章
- LeetCode OJ 83. Remove Duplicates from Sorted List
Given a sorted linked list, delete all duplicates such that each element appear only once. For examp ...
- 【一天一道LeetCode】#83. Remove Duplicates from Sorted List
一天一道LeetCode 本系列文章已全部上传至我的github,地址:ZeeCoder's Github 欢迎大家关注我的新浪微博,我的新浪微博 欢迎转载,转载请注明出处 (一)题目 Given a ...
- LeetCode OJ 82. Remove Duplicates from Sorted List II
Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numb ...
- LeetCode OJ 80. Remove Duplicates from Sorted Array II
题目 Follow up for "Remove Duplicates": What if duplicates are allowed at most twice? For ex ...
- LeetCode OJ:Remove Duplicates from Sorted Array II(移除数组中的重复元素II)
Follow up for "Remove Duplicates":What if duplicates are allowed at most twice? For exampl ...
- 【LeetCode】83 - Remove Duplicates from Sorted Array
Given a sorted array, remove the duplicates in place such that each element appear only once and ret ...
- LeetCode OJ 26. Remove Duplicates from Sorted Array
Given a sorted array, remove the duplicates in place such that each element appear only once and ret ...
- 【LeetCode OJ】Remove Duplicates from Sorted Array
题目:Given a sorted array, remove the duplicates in place such that each element appear only once and ...
- LeetCode OJ:Remove Duplicates from Sorted Array(排好序的vector去重)
Given a sorted array, remove the duplicates in place such that each element appear only once and ret ...
- 【LeetCode】83. Remove Duplicates from Sorted List 解题报告(C++&Java&Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 判断相邻节点是否相等 使用set 使用列表 递归 日 ...
随机推荐
- imx6移植librtmp
一.openssl交叉编译 1.下载 https://www.openssl.org/source/ 版本不要太高,刚开始版本高了,有些函数取消了,链接不上 使用1.0.1f即可 2.编译成共享库 . ...
- vim 查找命令
/要查找的内容 自光标起始位置向下查找 ?要查找的内容 自光标起始位置向上查找
- spring 解决中文乱码问题
spring 解决中文乱码问题 使用spring的前提下在web.xml中配置 <filter> <filter-name>encodingFilter</filter- ...
- [LOJ#2330]「清华集训 2017」榕树之心
[LOJ#2330]「清华集训 2017」榕树之心 试题描述 深秋.冷风吹散了最后一丝夏日的暑气,也吹落了榕树脚下灌木丛的叶子.相识数年的Evan和Lyra再次回到了小时候见面的茂盛榕树之下.小溪依旧 ...
- Linux 程序编译过程的来龙去脉
大家肯定都知道计算机程序设计语言通常分为机器语言.汇编语言和高级语言三类.高级语言需要通过翻译成机器语言才能执行,而翻译的方式分为两种,一种是编译型,另一种是解释型,因此我们基本上将高级语言分为两大类 ...
- jspspy database help
.
- vue中通过路由跳转的三种方式
原文:https://blog.csdn.net/qq_40072782/article/details/82533477 router-view 实现路由内容的地方,引入组件时写到需要引入的地方需要 ...
- CSS3 基本属性 浅析(含选择器、背景阴影、3D转换、动画等)
1渐进增强原则 2私有前缀 不同浏览器在发布不同版本(一般测试版)时会加前缀,新增属性加上前缀进行支持测试: Chrome浏览器:-webkit-border-radius: 5px; ...
- Java数据结构-------Map
常用Map:Hashtable.HashMap.LinkedHashMap.TreeMap 类继承关系: HashMap 1)无序: 2)访问速度快: 3)key不允许重复(只允许存在一个null ...
- socket介绍(webService适用场景)
1.使用场景 - 不同的移动客户端访问 - 需要访问第三方的项目 2.访问第三方应用的方式 ISO的七层模型 : 物理层.数据链路层.网络层.传输层.表示层.会话 ...