Remove Duplicates from Sorted Array
来源:互联网 发布:怎么订购淘宝视频服务 编辑:程序博客网 时间:2024/05/20 07:19
常规做法很普通,时间复杂度是O(n^2),那么如何使得时间复杂度为O(n)呢,可以采用下列算法:
class Solution {public: int removeDuplicates(int A[], int n) { int index=1; int i; if(n==0) return 0; for(i=1;i<n;i++) { if(A[i]!=A[i-1]) { A[index]=A[i]; index++; } } return index; }};
0 0
- Remove Duplicates from Sorted Array
- Remove Duplicates from Sorted Array
- Remove Duplicates from Sorted Array
- Remove Duplicates from Sorted Array
- Remove Duplicates from Sorted Array
- Remove Duplicates from Sorted Array
- Remove Duplicates From Sorted Array
- Remove Duplicates from Sorted Array
- Remove Duplicates from Sorted Array
- Remove Duplicates from Sorted Array
- Remove Duplicates from Sorted Array
- Remove Duplicates from Sorted Array
- Remove Duplicates from Sorted Array
- Remove Duplicates from Sorted Array
- Remove Duplicates from Sorted Array
- Remove Duplicates from Sorted Array
- Remove Duplicates from Sorted Array
- Remove Duplicates from Sorted Array
- Attribute "scope" must be declared for element type "bean"
- BZOJ 3747线段树 &&纪念整完了ubuntu
- 美语音标 [s]相关的变音
- Android多媒体系统的结构
- pat1061
- Remove Duplicates from Sorted Array
- C语言:常用算法
- BZOJ 3576 (HNOI 2014)江南乐 (博弈)
- DP入门50题(2)——NYoj252 01串
- 动态规划
- SpringMVC中的参数组装:HandlerMethodArgumentResolver
- leetcode maximum gap
- IOS开发学习中的基础知识究竟有多重要?
- C++多态技术