Remove Duplicates from Sorted Array

来源:互联网 发布:linux连接数 编辑:程序博客网 时间:2024/06/06 02:53

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].

译文:

给定一个排序的数组,删除重复的位置,使每个元素只显示一次

并返回新的长度。
不要为另一个数组分配额外的空间,您必须使用常量内存来执行此操作。
例如,给定输入数组A = [1,1,2],
你的函数应该返回length = 2,A现在是[1,2]。