Question
Given a sorted array nums, 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 by modifying the input array in-place with O(1) extra memory.
Analysis
Use two pointer:
- record current index postion
- iterate array and compare element with cur postion if the value is different replace the nums[cur++] = nums[fast]
Complexity
Time Complexity: O(n)
Solution
1 |
public int (int[] nums) { |
近期评论