Leetcode_Remove Duplicates from Sorted Array II
来源:互联网 发布:数据库前置库 编辑:程序博客网 时间:2024/05/18 03:23
Follow up for "Remove Duplicates":
What if duplicates are allowed at most twice?
For example,
Given sorted array A = [1,1,1,2,2,3]
,
Your function should return length = 5
, and A is now [1,1,2,2,3]
.
class Solution {public: int removeDuplicates(int A[], int n) { if(n<2) return n; int start=0,cur=1; int cnt=0; while(cur<=n-1){ if(A[start]==A[cur]){ cnt++; if(cnt>1){ cur++; } else{ A[++start]=A[cur++]; } } else{ cnt=0; A[++start]=A[cur++]; } } return start+1; }};
0 0
- 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
- LeetCode_Remove Duplicates from Sorted Array
- leetcode_Remove Duplicates from Sorted Array
- LeetCode_Remove Duplicates from Sorted Array
- LeetCode_remove-duplicates-from-sorted-array
- LeetCode_Remove Duplicates from Sorted Array
- Leetcode_remove-duplicates-from-sorted-array-ii (c++ and python version)
- Leetcode_remove-duplicates-from-sorted-list-ii
- LeetCode_Remove Duplicates from Sorted List II
- LeetCode_Remove Duplicates from Sorted List
- LeetCode_remove-duplicates-from-sorted-list
- LeetCode: Remove Duplicates from Sorted Array II
- [Leetcode] Remove Duplicates from Sorted Array II
- LeetCode: Remove Duplicates from Sorted Array II
- 机器学习-回归及分类问题总结
- Surprising Strings(STL)
- OC中的方法
- Acdream 1148 GCD SUM 莫比乌斯
- 对排序的总结&&二分查找
- Leetcode_Remove Duplicates from Sorted Array II
- HDU 4355 Party All the Time (三分算法的应用(含三分算法的讲解))
- uvalive 4997 ABCD Tiles
- Leetcod_Remove Duplicates from Sorted Array
- ZOJ 1639
- DOM(文档对象模型)
- OC 基础知识
- UVA 11489 搜索
- ios 关于图片读取