package leetcode;

import java.util.ArrayList;
import java.util.List;

/**
 * https://leetcode.com/problems/different-ways-to-add-parentheses/
 */
public class Problem241 {
    public List<Integer> diffWaysToCompute(String input) {
        if (input.length() == 1) {
            List<Integer> list = new ArrayList<>();
            list.add(Integer.valueOf(input));
            return list;
        }
        List<Integer> result = new ArrayList<>();
        for (int i = 0; i < input.length()-1; i++) {
            if (input.charAt(i) == '+' || input.charAt(i) == '-'
                || input.charAt(i) == '*') {
//                System.out.println("left: " + input.substring(0, i+1));
                List<Integer> left = diffWaysToCompute(input.substring(0, i+1));
//                System.out.println("right: " + input.substring(i+1, input.length()));
                List<Integer> right = diffWaysToCompute(input.substring(i+1, input.length()));
                for (int l : left) {
                    for (int r : right) {
                        if (input.charAt(i) == '+') {
                            result.add(l + r);
                        } else if (input.charAt(i) == '-') {
                            result.add(l - r);
                        } else if (input.charAt(i) == '*') {
                            result.add(l * r);
                        }
                    }
                }
            }
        }
        return result;
    }

    public static void main(String[] args) {
        Problem241 prob = new Problem241();
        for (int i : prob.diffWaysToCompute("2-1-1")) {
            System.out.println(i);
        }
    }
}

@@ -464,17 +464,17 @@
 int i = 
-0
+1
 ; i %3C in
@@ -489,15 +489,16 @@
 th()
--1
 ; i
-++
+ += 2
 ) %7B%0A
@@ -611,82 +611,8 @@
 ) %7B%0A
-//                System.out.println(%22left: %22 + input.substring(0, i+1));%0A
     
@@ -686,98 +686,8 @@
 0, i
-+1));%0A//                System.out.println(%22right: %22 + input.substring(i+1, input.length()
 ));%0A
@@ -1483,20 +1483,341 @@
 ;%0A        %7D%0A
+        System.out.println(%22----------------------------%22);%0A        for (int i : prob.diffWaysToCompute(%222*3-4*5%22)) %7B%0A            System.out.println(i);%0A        %7D%0A        System.out.println(%22----------------------------%22);%0A        for (int i : prob.diffWaysToCompute(%2211%22)) %7B%0A            System.out.println(i);%0A        %7D%0A
     %7D%0A%7D%0A

Update problem 241 (still incorrect)