leetcode第一刷_Remove Duplicates from Sorted Array II
来源:互联网 发布:怎样更改域名dns 编辑:程序博客网 时间:2024/06/05 09:19
水题。
我之前说过包含至多几个至少几个的问题都比较难,这个题可是让我大脸了。至多可以重复一次,那就重复次数多于两次再计算重复,否则的话像普通的数据一样直接按照重复次数前移就可以了嘛。不过说归说,这种inspace的思想还是有些用处的,数组这种实现方式致命的缺点就是删除或者添加中间的元素代价太大,因为不好把握数据的最终位置。这个题是一种情况,合并两个排序好的数组也是一个例子。
class Solution {public: int removeDuplicates(int A[], int n) { int past = A[0], due = 0, tpdue = 1; for(int i=1;i<n;i++){ if(A[i] == past){ tpdue++; if(tpdue>2){ due++; }else{ A[i-due] = A[i]; } }else{ past = A[i]; A[i-due] = A[i]; tpdue = 1; } } return n-due; }};
0 0
- leetcode第一刷_Remove Duplicates from Sorted Array II
- leetcode第一刷_Remove Duplicates from Sorted List II
- LeetCode 26_Remove Duplicates from Sorted Array
- 0026_Remove Duplicates from Sorted Array
- 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
- jquery 用alert警告,要加return false
- AngularJs学习笔记--Dependency Injection(DI,依赖注入)
- XCL-Charts画曲线图(CurveChart)
- WebXone V2400 Sp1发布!
- AngularJs学习笔记--Understanding the Model Component
- leetcode第一刷_Remove Duplicates from Sorted Array II
- AngularJs学习笔记--Understanding the Controller Component
- AngularJs学习笔记--E2E Testing
- 稳定排序和不稳定排序
- AngularJs学习笔记--Understanding Angular Templates
- 人脸识别原理检测及实现
- AngularJs学习笔记--Using $location
- CGLib动态代理
- 例解基于UML的面向对象分析与设计