LeetCode 80 Remove Duplicates from Sorted Array II
来源:互联网 发布:nob2b外贸搜索软件 编辑:程序博客网 时间:2024/05/17 02:23
题目
分析
对待这种题我一般就是把需要除去的数赋予一个很大的值,最后经过一个sort,所有不需要的数就到最后面去了。
题解
class Solution {public: int removeDuplicates(int A[], int n) { int temp; int length=1; int count=0; if(n==0) return 0; temp=A[0]; for(int i=1;i<n;i++){ if(A[i]==temp){ length++; if(length>2){ A[i]=65536; count++; length=2; } } else{ length=1; temp=A[i]; } } sort(A,A+n); return n-count; }};
0 0
- 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
- Leetcode: Remove Duplicates from Sorted Array II
- [LeetCode] Remove Duplicates from Sorted Array II
- EditText:文本编辑框
- 你为Windows Server 2003终止支持做好准备了吗?
- 利用arm开发板交叉编译opencv249错误汇总
- js guid
- 为什么你写不好一个快速排序?关于
- LeetCode 80 Remove Duplicates from Sorted Array II
- libx264 api example
- 使用Node.js开发一个在线聊天应用——编写前台
- serialVersionUID作用
- twitter update(分享)失败
- Servlet获取客户端浏览器信息和客户端的操作系统
- 4.8 Linux常用命令-关机重启命令
- 十分钟搞清字符集和字符编码
- js - jquery闭包+js面向对象实例