<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 使用列表 递归 日 ...
随机推荐
- zookeeper 下载安装
下载:wget https://www-us.apache.org/dist/zookeeper/zookeeper-3.4.13/zookeeper-3.4.13.tar.gz 解压:tar -zx ...
- node中fileSystem改promise
请注意,fs的大部分函数回调只会返回一个error参数,所以只要判断error为false的情况下就返回成功,无论有没有第二个参数. 另外exists需要单独包装,因为第一个参数就代表返回内容 con ...
- HTML5 新增绘图功能
<!DOCTYPE html> <html> <head lang="en"> <title></title> < ...
- BZOJ 1087:[SCOI2005]互不侵犯King(状压DP)
[SCOI2005]互不侵犯King [题目描述] 在N×N的棋盘里面放K个国王,使他们互不攻击,共有多少种摆放方案.国王能攻击到它上下左右,以及左上左下右上右下八个方向上附近的各一个格子,共8个格子 ...
- 荔枝丹(litchi)
荔枝丹(litchi) 题目描述 绛雪艳浮红锦烂,玉壶光莹水晶寒. 高名已许传新曲,芳味曾经荐大官. 乌府日长霜署静,几株斜覆石栏杆. --明·陈辉<荔枝> 荔枝(丹),拼音为lizhid ...
- HDR 高动态范围图像
以下来源于百度百科: 高动态范围图像(High-Dynamic Range,简称HDR),相比普通的图像,可以提供更多的动态范围和图像细节,根据不同的曝光时间的LDR(Low-Dynamic Rang ...
- nodejs+express+mongodb搭建博客
https://github.com/lanleilin/sayHelloBlog 是可以运行的 https://github.com/lanleilin/sayHelloBlog 文件结构如下: c ...
- 清理雪道(bzoj 2502)
Description 滑雪场坐落在FJ省西北部的若干座山上. 从空中鸟瞰,滑雪场可以看作一个有向无环图,每条弧代表一个斜坡(即雪道),弧的方向代表斜坡下降的方向. 你的团队负责每周定时 ...
- 洛谷 [P3723] 礼物
FFT https://www.luogu.org/problemnew/solution/P3723 重点在于构造卷积的形式 #include <iostream> #include & ...
- cookie中存储json
原文发布时间为:2009-12-14 -- 来源于本人的百度文章 [由搬家工具导入] http://www.denisdeng.com/?p=563 最近的一个项目需要在cookie中存储json对象 ...