package leetcode;

/**
 * https://leetcode.com/problems/target-sum/
 */
public class Problem494 {
    public int findTargetSumWays(int[] nums, int S) {
        // TODO
        return 0;
    }

    public static void main(String[] args) {
        Problem494 prob = new Problem494();
        System.out.println(prob.findTargetSumWays(new int[]{1, 1, 1, 1, 1}, 3)); // 5
    }
}

@@ -157,32 +157,44 @@
     
-// TODO%0A        return
+return findTargetSumWays(nums, S,
  0
+)
 ;%0A  
@@ -207,21 +207,22 @@
    p
-ublic
+rivate
  static 
 void
@@ -221,164 +221,266 @@
 tic 
-void main(String%5B%5D args) %7B%0A        Problem494 prob = new Problem494();%0A        System.out.println(prob.findTargetSumWays(new int%5B%5D%7B1, 1, 1, 1, 1%7D, 3)); // 5
+int findTargetSumWays(int%5B%5D nums, int s, int idx) %7B%0A        if (idx == nums.length) %7B%0A            return (s == 0) ? 1 : 0;%0A        %7D%0A        return findTargetSumWays(nums, s - nums%5Bidx%5D, idx + 1) +%0A            findTargetSumWays(nums, s + nums%5Bidx%5D, idx + 1);
 %0A   

Solve problem 494