Remove Duplicated
Given an array of integers, remove the duplicate numbers in it.
You should:
Do it in place in the array.
Move the unique numbers to the front of the array.
Return the total number of the unique numbers.
Example
Givennums=[1,3,1,4,4,2]
, you should:
Move duplicate integers to the tail of nums=>nums=
[1,3,4,2,?,?]
.Return the number of unique integers in nums=>
4
.
Actually we don't care about what you place in?
, we only care about the part which has no duplicate integers.
Note
要先排序的。右指针遍历,左指针来判断特殊情况
一般都操作不一样的,把右指针的数换到左指针的后一位,如果所有数字都是不一样的左指针会一直比右指针慢一格,右指针会和自己换,所以也是work的。
所以最后返回就是左指针的位置加一
Code
Last updated