Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
42 lines (38 loc) · 1.49 KB

File metadata and controls

42 lines (38 loc) · 1.49 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
public class Solution {
public List<Integer> diffWaysToCompute(String input) {
List<Integer> result = new ArrayList<Integer>();
int k = 0;
int curr = 0;
while (k < input.length() && Character.isDigit(input.charAt(k))) {
curr = curr * 10 + (int)input.charAt(k) - (int)'0';
k += 1;
}
if (k == input.length()) {
result.add(curr);
return result;
}
for (int i = 0; i < input.length(); i++) {
if (Character.isDigit(input.charAt(i)) == false) {
List<Integer> left = diffWaysToCompute(input.substring(0, i));
List<Integer> right = diffWaysToCompute(input.substring(i+1, input.length()));
for (int m = 0; m < left.size(); m++) {
for (int n = 0; n < right.size(); n++) {
int op1 = left.get(m);
int op2 = right.get(n);
int r = 0;
char op = input.charAt(i);
if (op == '-') {
r = op1 - op2;
} else if (op == '+') {
r = op1 + op2;
} else {
r = op1 * op2;
}
result.add(r);
}
}
}
}
return result;
}
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.