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);
    }
}
//方法二:深度优先搜索

leetcode 中等难度

上一篇:码云官网gitee.com 打不开


下一篇:ERROR 1273 (HY000): Unknown collation: 'utf8mb4_0900_ai_ci' Query OK, 0 rows affected (0.00 sec) ERROR 11462S02): Table 'fizz_manager.blade_user' doesn't exist