【leetcode】Remove Duplicates from Sorted Array II
来源:互联网 发布:linux下web服务器配置 编辑:程序博客网 时间:2024/04/29 23:40
class Solution {public: int removeDuplicates(int A[], int n) { // Start typing your C/C++ solution below // DO NOT write int main() function if(n==0||n==1||n==2)//n<=2的情况 return n; int loc=0;//计数新数组中的元素 int loc1=0; while(loc1+2<=n-1) { if(A[loc1]==A[loc1+2])//因为A[]是有序的,所以不用比较A[loc1+1] loc1++; else A[loc++]=A[loc1++]; } if(loc1<=n-1)//处理A[]末尾处的两个 A[loc++]=A[loc1++]; if(loc1<=n-1) A[loc++]=A[loc1++]; return loc; }};
- 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
- JBossESB教程(三)——别人不会对你说的,第一个实例
- substance使用问题汇总(小试牛刀)
- php c扩展
- Arithmetic Progressions CC COUNTARI
- uva 11181 - Probability|Given(枚举,贝叶斯公式)
- 【leetcode】Remove Duplicates from Sorted Array II
- win7创建虚拟wifi
- c++模板类
- .NET重构—单元测试重构
- CreateThread与_beginthreadex本质区别
- IncrediBuild分布式编译环境搭建
- 未知元素个数遍历一遍随机等概率取出一个
- 惊人的答案:平均要取多少个(0,1)中的随机数才能让和超过1
- 左移字符