Timeout on a data set

  • 0

    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:

Log in to reply

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