[LeetCode] 80. Remove Duplicates from Sorted Array II
来源:互联网 发布:js1-400拌和机技术数据 编辑:程序博客网 时间:2024/06/05 07:15
Follow up for “Remove Duplicates”:
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, 2 and 3. It doesn’t matter what you leave beyond the new length.
class Solution {public: int removeDuplicates(vector<int>& nums) { if (nums.size() == 0) return 0; int k = 1, SegLen = 1; for (int i = 1; i < nums.size(); i++) { if (nums[i] == nums[k - 1]) { if (SegLen < 2) { nums[k++] = nums[i]; SegLen++; } } else { nums[k++] = nums[i]; SegLen = 1; } } return k; }};
阅读全文
0 0
- leetcode——26. Remove Duplicates from Sorted Array && 80. Remove Duplicates from Sorted Array II
- LeetCode 26. Remove Duplicates from Sorted Array && 80. Remove Duplicates from Sorted Array II
- leetcode.array--80. Remove Duplicates from Sorted Array II
- LeetCode: Remove Duplicates from Sorted Array II
- [Leetcode] Remove Duplicates from Sorted Array II
- LeetCode: Remove Duplicates from Sorted Array II
- [Leetcode] Remove Duplicates from Sorted Array II
- [LeetCode] Remove Duplicates from Sorted Array II
- [leetcode] Remove Duplicates from Sorted Array II
- [LeetCode]Remove Duplicates from Sorted Array II
- [leetcode]Remove Duplicates from Sorted Array II
- LeetCode-Remove Duplicates from Sorted Array II
- [leetcode] Remove Duplicates from Sorted Array II
- LeetCode - Remove Duplicates from Sorted Array II
- LeetCode:Remove Duplicates from Sorted Array II
- LeetCode | Remove Duplicates from Sorted Array II
- Leetcode: Remove Duplicates from Sorted Array II
- 【leetcode】Remove Duplicates from Sorted Array II
- MD5理解
- 01背包问题收录.
- JZOJ1217. 软件开发(2017年8月B组)
- Android ConstraintLayout详解-使用可视化的方式来编写界面
- 【转载】Repodata is over 2 weeks old. Install yum-cron? Or run: yum makecache fast
- [LeetCode] 80. Remove Duplicates from Sorted Array II
- Android TV热键(快捷键、组合键)实现
- 注解(Annotation)基本概念
- 微服务架构的基础框架选择:Spring Cloud还是Dubbo?
- sturct和class的区别
- JS的编程实现
- Google/LintCode:E-Big Integer Addition
- Django实现用户登录
- 2017暑期集训Day 25 树状数组