why my code is wrong about: Remove Duplicates from Sorted Array


  • 0
    T

    why my code is wrong about: Remove Duplicates from Sorted Array

     ~~>! >! strikethrough text~~
    

    class Solution(object):
    def removeDuplicates(self, nums):
    """
    :type nums: List[int]
    :rtype: int
    """
    len_nums = len(nums)
    indexs=[]
    for i in range(len_nums-1):
    for j in range(i+1, len_nums, 1):
    if nums[i] == nums[j]:
    indexs.append(j)
    nums = [v for i, v in enumerate(nums) if i not in indexs]
    len_n = len(nums)
    print(nums)
    return len_n

    a = [1, 2, 3, 1, 2]
    s = Solution()
    s.removeDuplicates(a)


Log in to reply
 

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