2
int idx; // this index traverse the string in one pass, between different level of recursion4
public int calculate(String s) {5
idx = 0; // Initialization should be here9
private int helper(String s) {10
int res = 0, num = 0, preSign = 1, n = s.length();12
char c = s.charAt(idx++);13
if (c == '(') num = helper(s); // Let recursion solve the sub-problem14
else if (c >= '0' && c <= '9') num = num * 10 + c - '0';15
if (c == '+' || c == '-' || c == ')'16
|| idx == n) { // we need one more calculation when idx == n18
if (c == ')') return res; // end of a sub-problem20
preSign = c == '+' ? 1 : -1;