Remove Duplicates from Sorted Array II
来源:互联网 发布:淘宝天天特价怎么找 编辑:程序博客网 时间:2024/06/07 13:46
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]
.
与Remove Duplicates from Sorted Array很雷同!
int removeDuplicates(int A[], int n) { int current,index; int count; current = 1; index = 0; //取值很关键 count = 1; if(n <= 2 )return n; while(current < n) { if(A[current] == A[current-1]) { count++; if(count <= 2) { A[++index]=A[current];//主要在这个地方,小于2的重复,还是的覆盖! } current++; } else { count = 1; A[++index]=A[current]; current ++; } } return index+1 ; }
- LeetCode: Remove Duplicates from Sorted Array II
- [Leetcode] Remove Duplicates from Sorted Array II
- LeetCode: Remove Duplicates from Sorted Array II
- Remove Duplicates from Sorted Array II
- [Leetcode] Remove Duplicates from Sorted Array II
- [LeetCode] Remove Duplicates from Sorted Array II
- Remove Duplicates from Sorted Array II
- [leetcode] Remove Duplicates from Sorted Array II
- Remove Duplicates from Sorted Array II
- Remove duplicates from sorted array II
- Remove Duplicates from Sorted Array II
- [LeetCode]Remove Duplicates from Sorted Array II
- Remove Duplicates from Sorted Array II
- Remove Duplicates from Sorted Array II
- Remove Duplicates from Sorted Array II
- Remove Duplicates from Sorted Array II
- [leetcode]Remove Duplicates from Sorted Array II
- LeetCode-Remove Duplicates from Sorted Array II
- SequoiaDB创始人:比MongoDB领先一到两年 打造企业级NoSQL数据库
- 从今天起用此博客记录那些对我有帮助的网页(不断更新)
- 试试发代码
- 设计包含 min 函数的栈
- TCP/IP协议簇一览图
- Remove Duplicates from Sorted Array II
- 低成本和高性能MySQL云数据的架构探索
- leetcode Permutation Sequence
- 十五周——带姓名的成绩单
- 文本挖掘过程(Text Mining)
- ftl常用标签和语法
- ios开发(十三) singlton
- VS2008恢复默认界面设置
- opencv 在指定位置显示图像