Timeout on a data set


  • 0
    D

    Can someone help to take a look the following code?

    class Solution(object):
        def findTargetSumWays(self, nums, S):
            def dfs(nums, target, start, cur):
                sums = 0
                if start == len(nums):
                    return 1 if cur == target else 0
                sums+=dfs(nums, target, start+1, cur+nums[start])
                sums+=dfs(nums, target, start+1, cur-nums[start])
                return sums;
            return dfs(nums, S, 0, 0)
    

    It hits TLE on the following data set:
    [10,9,6,4,19,0,41,30,27,15,14,39,33,7,34,17,24,46,2,46]
    45


Log in to reply
 

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