Tag: array, level : easy
Solution:
maintain two pointers, one iterate the whole array, one keep the tail valid element position.
when the iterated pointer meet a valid element, assign it the the tail position, and make the tail pointer one step further.
When the iteration done, the tail position is the result.
Time: O(n), Space: O(1)
网友评论