Remove Duplicates from Sorted Array
来源:互联网 发布:php与c进行socket通信 编辑:程序博客网 时间:2024/06/06 01:11
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(A==NULL || n<=0) return 0; int index=0; for(int i=1;i<n;i++){ if(A[index]!=A[i]){ A[++index]=A[i]; } } return index+1; }};
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
- hdu4883 TIANKENG’s restaurant 模拟下就好了
- 严环导科官导呵狼肥倩卮
- 蛇形填数
- poj 3468 A Simple Problem with Integers
- 如何用pdf转换器快速转换PDF文件
- Remove Duplicates from Sorted Array
- ubuntu中SSH的安装
- Windows下安装Resin及配置详解与发布应用
- poj3009 简单的深搜
- C++ 函数使用形参传入二维数组实参的方法
- 常用的Objective-C开源类库
- PayPal:比特币潜力绝不仅限支付方式
- mysql常用命令操作
- Linux驱动经典面试题目