L521 Remove Duplicate Numbers in Array
Description
Given an array of integers nums
, logically remove the duplicate elements and return the length of the removed array n
such that the first n
elements of the array nums
contain all the elements of the original array nums
after de-duplication by the de-duplication operation.
You should:
Do it in place in the array.
Put the element after removing the repetition at the beginning of the array.
Return the number of elements after removing duplicate elements.
Wechat reply 【Google】 get the latest requent Interview questions. (wechat id : jiuzhang1104)
You don't need to keep the original order of the integers.
Example
Example 1:
Explanation:
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.
Example 2:
Challenge
Do it in O(n) time complexity.
Do it in O(nlogn) time without extra space.
Last updated
Was this helpful?