898ms c Code, beats 13%


  • 0
    D
    void calculate(int*, int, int, int, int*, int);
        
    int findTargetSumWays(int* nums, int numsSize, int S) {
        int count = 0;
        calculate(nums, 0, 0, S, &count, numsSize);
        return count;
    }
    
    void calculate(int* nums, int i, int sum, int S, int* count, int size) {
        if (i == size) {
            if (sum == S) {
                *count+=1;
            }
        } else {
            calculate(nums, i + 1, sum + nums[i], S, count, size);
            calculate(nums, i + 1, sum - nums[i], S, count, size);
        }
    }
    

Log in to reply
 

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