Python: a easy-understanding way to do this

  • -2
    def firstMissingPositive(self, nums):
        :type nums: List[int]
        :rtype: int
        copy_nums = []
        for num in nums:
            if num > 0:
        if not copy_nums:
            return 1
        top = max(copy_nums)
        empty_stack = []
        for i in xrange(top):
        for num in copy_nums:
            empty_stack[num-1] = num
        for pos,value in enumerate(empty_stack):
            if value == "empty":
                return pos+1
        return top+1

Log in to reply

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