python solution


  • 0
    R
    class Solution(object):
        def removeDuplicates(self, nums):
            """
            :type nums: List[int]
            :rtype: int
            """
            p = 0
            dic = {}
            for i in nums:
                if i in dic.keys():
                    dic[i] = dic[i] + 1
                if i not in dic.keys():
                    dic[i] = 1
            for j in dic.keys():
                if dic[j] >= 2:
                   nums[p : p + dic[j]] = [j] * 2
                   p = p + 2
                if dic[j] < 2:
                    nums[p : p + dic[j]] = [j] * dic[j]
                    p = p + dic[j]
            nums.sort()
            return p

  • 0
    H

    @robocen2016 it's a lot going on there.


Log in to reply
 

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