LeetCode: Remove Duplicates from Sorted Array II
来源:互联网 发布:tcp ip协议 网络编程 编辑:程序博客网 时间:2024/04/29 21:42
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) { // Start typing your C/C++ solution below // DO NOT write int main() function if(n <= 1){return n;} int pos = 0; for(int i = 0; i< n; ++i){ int count = 0; while(i < n- 1 && A[i] == A[i +1]){ i++; count++; } if(count > 1){ count = 1; } if(count){ A[pos++] = A[i]; } A[pos++] = A[i]; } return pos; }};
- 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
- Leetcode: Remove Duplicates from Sorted Array II
- [LeetCode] Remove Duplicates from Sorted Array II
- Leetcode Remove Duplicates from Sorted Array II
- 关于IE 延迟加载activex和插件未激活问题。
- vc++之CSize
- 期末考试月来临,各种大作业啊
- Java 文件上传组件 Apache Commons FileUpload 应用指南
- ie6,ie7,ie8 css bug兼容解决方法
- LeetCode: Remove Duplicates from Sorted Array II
- Blender 三维绘图及渲染软件(优秀强大跨平台遵循 GPL 许可证)
- pca算法的实现
- OpenCV基础结构
- QTP新建函数库,并且如何在一个test里添加该函数库
- Android TouchEvent 分发流程
- 裘宗燕:C/C++ 语言中的表达式求值
- 一些有用的书签网站整理
- LeetCode: Remove Duplicates from Sorted List