Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
different ways to add parenthesis leetcode #241
//'main' method must be in a class 'Rextester'. //Compiler version 1.8.0_111 import java.util.*; import java.lang.*; class Rextester { public static List<Integer> diffWaysToCompute(String input) { List<Integer> out = new ArrayList<>(); try{ out.add(Integer.parseInt(input)); return out; }catch(NumberFormatException e){} for(int i = 0;i<input.length();i++){ if(input.charAt(i)=='+' || input.charAt(i)=='-' || input.charAt(i)=='*'){ List<Integer> ret1 = diffWaysToCompute(input.substring(0,i)); List<Integer> ret2 = diffWaysToCompute(input.substring(i+1)); for(int sum1:ret1){ for(int sum2:ret2){ int res = 0; switch(input.charAt(i)){ case '+': res = sum1+sum2; break; case '-': res = sum1- sum2; break; case '*': res = sum1* sum2; break; } out.add(res); } } } } return out; } public static void main(String args[]) { System.out.println("Hello, World!"); List<Integer> out = diffWaysToCompute("11"); for(int i:out) System.out.print(i+" "); } }
run
|
edit
|
history
|
help
0
calc exp gxb2
Magic No.
Coding Numbers - Polindrome
Escaping Literals (Table of records)
InnerClass vs. Anonymous vs. Lambda...
Человечки
queue_using_stack
get top k frequent elements ( Priority Queue implementation ) Language: Editor: Layout:
Java Replace Method
Test