class Solution {
int index;
char[] ch;
public boolean parseBoolExpr(String expression) {
ch = expression.toCharArray();
index = 0;
return dfs();
}
public boolean dfs() {
if (ch[index] == 'f') {
index++;
return false;
}
if (ch[index] == 't') {
index++;
return true;
}
char op = ch[index];
index += 2;
boolean res = true;
if (op == '|') res = false;
while(ch[index] != ')') {
if (ch[index] == ',') {
index ++;
} else {
boolean nextBool = dfs();
if (op == '|') {
res = res | nextBool;
} else {
res = res & nextBool;
}
}
}
index ++;
if (op == '!') {
res = !res;
}
return res;
}
}
标签:index,ch,return,++,res,1106,boolean,表达式,布尔
From: https://www.cnblogs.com/eiffelzero/p/16859938.html