leetcode 中等难度
作者:互联网
L494
//方法一:回溯法
class Solution {
public static int findTargetSumWays(int[] nums, int target) {
cnt =0;
recurve(nums, 0, 0, target);
return cnt;
}
static int cnt = 0;
public static void recurve(int[] nums, int n, int sum, int target) {
if (n == nums.length) {
if (sum == target) cnt++;
return;
}
recurve(nums, n + 1, sum + nums[n], target);
recurve(nums, n + 1, sum - nums[n], target);
}
}
//方法二:深度优先搜索
标签:cnt,target,nums,int,sum,中等,leetcode,难度,recurve 来源: https://www.cnblogs.com/zhouyu0-0/p/15213242.html