Leetcode #80 Remove Duplicates from Sorted Array II
2015-08-01 14:01
393 查看
Follow up for "Remove Duplicates":
What if duplicates are allowed at most twice?
For example,
Given sorted array nums =
Your function should return length =
It doesn't matter what you leave beyond the new length.
Difficulty:Medium
和I 类似的方法
What if duplicates are allowed at most twice?
For example,
Given sorted array nums =
[1,1,1,2,2,3],
Your function should return length =
5, with the first five elements of nums being
1,
1,
2,
2and
3.
It doesn't matter what you leave beyond the new length.
Difficulty:Medium
和I 类似的方法
int removeDuplicates(vector<int>& nums) { int len = nums.size(); if(len==0) return 0; int temp = 2147483647,cou=1; for(int i = 1;i<len;i++) { if(i-2>=0&&((nums[i]==nums[i-1]&&nums[i]==nums[i-2])||nums[i]==temp)) { temp = nums[i]; nums[i] = 2147483647; cou--; } cou++; } sort(nums.begin(),nums.end()); return cou; }
相关文章推荐
- HDU 1695 GCD 莫比乌斯第二发
- python模块 - 其它常用模块推荐
- js数组去重的几种方法
- hide the navigationBar and tabBar
- Selenium2学习-022-WebUI自动化实战实例-020-JavaScript 在 Selenium 自动化中的应用实例之二(获取浏览器显示区域大小)
- Android学习笔记之Context
- linux 基本命令之fg、bg、jobs、&、ctrl + z
- js 开发框架集合
- 离钱越近,才能赚钱越‘稳’
- [二分+模拟]poj 3273 Monthly Expense
- 整除15问题
- Windows 10正式版为什么没有休眠选项? 找回win10休眠选项的方法
- php学习笔记_4_常量及魔法常量需要注意的点
- hdoj背包水题
- 1032. 挖掘机技术哪家强(20)
- ubuntu恢复模式下磁盘只读问题
- 暑假集训第三周第二阶段搜索 G - 迷宫问题
- Java方法工厂,接口,常用日期类Date面向对象,匿名内部类局部类
- android 时钟开发
- Cocos2d-x 3.2 项目源代码从Mac打包到安卓教程【转自:http://www.2cto.com/kf/201410/342649.html】