Python time limit too strict.


  • 0
    W

    I mean. If Java and C++ O(mn) solution can be AC.

    What's the point of limiting Python?

    This does't make any sense.

    Here is my code:

    '''

    def canPartition(self, nums):
    
        if (not nums):
            return True
            
        summary = sum(nums)
        if summary % 2 != 0: return False
        bound = summary / 2
        dp = [0 for j in xrange(bound + 1)]
        dp[0] = 1
        canreach = {0}
        
        for i in xrange(1, len(nums) + 1):
            newreach = set()
            for j in canreach:
                #print j
                if 0 <= j + nums[i-1] < bound + 1 and j + nums[i-1]:
                    #print j, nums[i-1], j+nums[i-1]
                    dp[j + nums[i-1]] = 1
                    newreach.add(j + nums[i-1])
            canreach |= newreach
            #print dp
                
        return dp[-1] == 1
    

    '''

    I even used a hashset to reduce to number of loops. My code shouldn't be that bad, huh?

    So, stop the ridiculous discrimination.

    @administrators


  • 0

    @whglamrock Done. Thanks for reporting. Your python code should get AC now.


  • 0
    W

    @1337c0d3r
    Thank you very much.


Log in to reply
 

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