Leetcod_Remove Duplicates from Sorted Array
来源:互联网 发布:数据库前置库 编辑:程序博客网 时间:2024/06/16 09:52
Given a sorted array, remove the duplicates in place such that each element appear only once and return the new length.
Do not allocate extra space for another array, you must do this in place with constant memory.
For example,
Given input array A = [1,1,2]
,
Your function should return length = 2
, and A is now [1,2]
.
class Solution {public: int removeDuplicates(int A[], int n) { if(n<=1) return n; int start=0,cur=1; while(cur <= n-1){ if(A[start]==A[cur]){ cur++; } else{ A[++start]=A[cur++]; } } return start+1; }};
0 0
- Leetcod_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
- Acdream 1148 GCD SUM 莫比乌斯
- 对排序的总结&&二分查找
- Leetcode_Remove Duplicates from Sorted Array II
- HDU 4355 Party All the Time (三分算法的应用(含三分算法的讲解))
- uvalive 4997 ABCD Tiles
- Leetcod_Remove Duplicates from Sorted Array
- ZOJ 1639
- DOM(文档对象模型)
- OC 基础知识
- UVA 11489 搜索
- ios 关于图片读取
- [LeetCode]Clone Graph 克隆图
- scanf的一些用法
- hdu 1569 方格取数——最大点权独立集