[LeetCode] Remove Duplicates from Sorted Array II
2015-06-09 21:39
489 查看
Well, an extension of Remove Duplicates from Sorted Array.
The program is fairly similar to that in this solution.
After playing with it for a while, you may notice that the code can be easily extended to accommodate 3, 4, ... duplicates by modifying lines 3, 4, 5 in a similar manner.
The program is fairly similar to that in this solution.
int removeDuplicates(vector<int>& nums) { if (nums.size() <= 2) return nums.size(); int pos = 1; for (int i = 2; i < nums.size(); i++) if (nums[i] != nums[pos] || nums[i] != nums[pos - 1]) nums[++pos] = nums[i]; return pos + 1; }
After playing with it for a while, you may notice that the code can be easily extended to accommodate 3, 4, ... duplicates by modifying lines 3, 4, 5 in a similar manner.
相关文章推荐
- java设计模式 ----工厂模式
- 两阶段提交协议(2PC)
- 模型 - 视图 - 控制器(MVC)详解
- POJ 2096 Collecting Bugs
- Statement和PreparedStatement的区别; 什么是SQL注入,怎么防止SQL注入?
- JavaScript编码规范
- java的四大特征
- leetcode - 4Sum
- Intent系列1——启动另外一个Activity
- 得到联系人数据
- 调度场算法与逆波兰表达式
- 【算法】字符串编辑距离
- Java线程
- easyUi的combotree绑定后台返回的json字符串(EasyUI+spring mvc+mybatis)
- Servlet3.0在文件上传时遇到的错误及解决方法
- Cookie类型:Session cookies(过期时间为空) + Persistent cookies
- 动词的种类
- 统计难题(map)
- 动词的种类
- 以图片为背景在其上添加组件不被覆盖