美文网首页
Remove element

Remove element

作者: 世界你好 | 来源:发表于2018-06-24 03:26 被阅读9次

    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)

    相关文章

      网友评论

          本文标题:Remove element

          本文链接:https://www.haomeiwen.com/subject/kfhjyftx.html