Tag: array, level: easy
Solution:
Using two pointers, use first pointer to iterate the whole array, second point to the position without duplicates.
When the first pointer get to an non-duplicated element, assign it the the second pointer, then move second pointer a step further.
After the first pointer finish the iteration, the second pointer is at the position of non-duplicates.
Time: O(n), space O(1)
https://github.com/Blankj/awesome-java-leetcode/blob/master/note/026/README.md
网友评论