Remove Duplicates from Sorted Array II
来源:互联网 发布:陆维网络图软件 编辑:程序博客网 时间:2024/06/10 23:31
Remove Duplicates from Sorted Array II
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==0) return 0; int idx = 0, count = 0 , i = 0; for ( i = 0; i < n ; i++) { if (i >0 && a[i] ==a[i-1]) { count++; if(count >= 3){ continue; } } else { count = 1; } a[idx++] = a[i]; } return idx; }};
0 0
- 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
- 黑马程序员--java基础复习之集合
- java命令模式
- BS的初步小结
- 圆投影匹配算法描述及实现
- zabbix应用之Low-level discovery监控磁盘IO
- Remove Duplicates from Sorted Array II
- UVA - 11578(背包类dp)
- 通过Edit Distance问题理解动态规划算法
- 编程之美 2013 全国挑战赛 资格赛 题目二 长方形
- RFID与物联网的关系。
- Mac下安装和管理Java
- 知识体系
- poj 1041 John's trip 欧拉路
- 一、Java图形化界面设计——容器(JFrame)