美文网首页算法提高之LeetCode刷题
Remove Duplicates from Sorted Ar

Remove Duplicates from Sorted Ar

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

    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

    相关文章

      网友评论

        本文标题:Remove Duplicates from Sorted Ar

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