LeetCode OJ--Remove Duplicates from Sorted List II *
http://oj.leetcode.com/problems/remove-duplicates-from-sorted-list-ii/
处理链表的范例
#include <iostream>
using namespace std; struct ListNode {
int val;
ListNode *next;
ListNode(int x) : val(x), next(NULL) {}
}; class Solution {
public:
ListNode *deleteDuplicates(ListNode *head) {
if(head == NULL) return head; ListNode dummy(INT_MIN);
dummy.next = head;
ListNode *prev = &dummy,*cur = head;
while(cur!= NULL)
{
bool duplicated = false;
while(cur->next != NULL && cur->val == cur->next->val)
{
duplicated = true;
cur = cur->next;
}
if(duplicated)
{
cur = cur->next;
continue;
}
prev->next = cur;
prev = prev->next;
cur = cur->next;
}
prev->next = cur;
return dummy.next;
}
}; int main()
{
ListNode *n1 = new ListNode();
ListNode *n2 = new ListNode();
ListNode *n3 = new ListNode();
ListNode *n4 = new ListNode();
ListNode *n5 = new ListNode();
ListNode *n6 = new ListNode();
ListNode *n7 = new ListNode();
n1->next = n2;
n2->next = n3;
n3->next = n4;
n4->next = n5;
n5->next = n6;
n6->next = n7;
ListNode *ans;
Solution myS;
ans = myS.deleteDuplicates(n1);
return ;
}
LeetCode OJ--Remove Duplicates from Sorted List II *的更多相关文章
- LeetCode OJ Remove Duplicates from Sorted Array II
Follow up for "Remove Duplicates":What if duplicates are allowed at most twice? For exampl ...
- LeetCode 80 Remove Duplicates from Sorted Array II [Array/auto] <c++>
LeetCode 80 Remove Duplicates from Sorted Array II [Array/auto] <c++> 给出排序好的一维数组,如果一个元素重复出现的次数 ...
- 【leetcode】Remove Duplicates from Sorted Array II
Remove Duplicates from Sorted Array II Follow up for "Remove Duplicates":What if duplicate ...
- [LeetCode] 80. Remove Duplicates from Sorted Array II ☆☆☆(从有序数组中删除重复项之二)
https://leetcode.com/problems/remove-duplicates-from-sorted-array-ii/discuss/27976/3-6-easy-lines-C% ...
- [leetcode] 80. Remove Duplicates from Sorted Array II (Medium)
排序数组去重题,保留重复两个次数以内的元素,不申请新的空间. 解法一: 因为已经排好序,所以出现重复的话只能是连续着,所以利用个变量存储出现次数,借此判断. Runtime: 20 ms, faste ...
- [LeetCode] 80. Remove Duplicates from Sorted Array II 有序数组中去除重复项 II
Given a sorted array nums, remove the duplicates in-place such that duplicates appeared at most twic ...
- [LeetCode] 82. Remove Duplicates from Sorted List II 移除有序链表中的重复项 II
Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numb ...
- [LeetCode] 82. Remove Duplicates from Sorted List II 移除有序链表中的重复项之二
Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numb ...
- [LeetCode] 80. Remove Duplicates from Sorted Array II 有序数组中去除重复项之二
Given a sorted array nums, remove the duplicates in-place such that duplicates appeared at most twic ...
- LeetCode 80. Remove Duplicates from Sorted Array II (从有序序列里移除重复项之二)
Follow up for "Remove Duplicates":What if duplicates are allowed at most twice? For exampl ...
随机推荐
- 理解 React,但不理解 Redux,该如何通俗易懂的理解 Redux?(转)
作者:Wang Namelos 链接:https://www.zhihu.com/question/41312576/answer/90782136来源:知乎 解答这个问题并不困难:唯一的要求是你熟悉 ...
- xheditor的参数配置详解
2.2. 初始化参数列表 2.3. API函数接口列表 2.4. 上传程序开发规范 2.5. 插件开发指南 2.6. 皮肤设计指南 2.2. 初始化参数列表 初始化参数示例代码: $('#elm1') ...
- ext笔记
命名 The top-level namespaces and the actual class names should be CamelCased. Everything else shoul ...
- iOS 优秀博客
中文 iOS/Mac 开发博客列表 GitHub 上排名前 100 的 Objective-C 项目简介 GitHub 上都有哪些值得关注学习的 iOS 开源项目? iOS开发系列文章(持续更新……) ...
- postcss.config.js配置文件的配置方法
module.exports = { plugins: { 'autoprefixer': {}, } }
- mysqldump导出备份数据库报Table ‘performance_schema.session_variables‘ doesn‘t exist
今天在bash进行本地数据库往云端数据库导数据的时候,在本地导出.sql文件这第一步就出现了错误问题,导出sql文件的命令: mysqldump -u 用户名 -p 数据库名 > xxx.sql ...
- (61)zabbix网络发现规则配置实战/详解
开始配置.首先,我们需要定义发现规则,用于扫描.步骤如下 第一步 Configuration >>Discovery>>Create rule,编辑网络发现规则 如上配置,za ...
- lsof指令使用简介
lsof替代了netstat和ps的全部工作.它可以带来那些工具所能带来的一切,而且要比那些工具多得多 最重要的是,当你给它传递选项时,默认行为是对结果进行“或”运算.因此,如果是用-i来拉出一个端口 ...
- PHP操作MySQL事务实例
PHP与MYSQL事务处理 一般来说,事务都应该具备ACID特征.所谓ACID是Atomic(原子性),Consistent(一致性),Isolated(隔离性),Durable(持续性)四个词的首字 ...
- perl学习笔记之:正则表达式
Perl 中的正则表达式 正则表达式的三种形式 正则表达式中的常用模式 正则表达式的 8 大原则 正则表达式是 Perl 语言的一大特色,也是 Perl 程序中的一点难点,不过 ...