Python O(N) time O(1) space solution


  • 0

    '''
    class Solution(object):
    def removeDuplicates(self, nums):
    """
    :type nums: List[int]
    :rtype: int
    """
    count = 0
    begin = 0
    r = []
    while begin < len(nums):
    sub_count = 0
    current_num = nums[begin]
    while begin < len(nums) and current_num == nums[begin]:
    if sub_count < 2:
    sub_count += 1
    count += 1
    begin += 1
    else:
    del nums[begin]
    return count
    '''


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.