MCPcopy Index your code
hub / github.com/Tiwarishashwat/InterviewCodes / parseBoolExpr

Method parseBoolExpr

ParsingABooleanExpression.java:2–25  ·  view source on GitHub ↗
(String expression)

Source from the content-addressed store, hash-verified

1class Solution {
2 public boolean parseBoolExpr(String expression) {
3 // 2n
4 Stack<Character> stack = new Stack<>();
5 int n = expression.length();
6 // n + n
7 for(int i=0;i<n;i++){ //N
8 char ch = expression.charAt(i);
9 if(ch==')'){
10 ArrayList<Character> list = new ArrayList<>();
11 while(stack.peek()!='('){ //k
12 list.add(stack.pop());
13 }
14 stack.pop(); //remove '('
15 char op = stack.pop();
16 char ans = evaluate(list,op); //k
17 stack.push(ans);
18 }else{
19 if(ch!=','){
20 stack.push(ch);
21 }
22 }
23 }
24 return stack.peek() == 't';
25 }
26 public char evaluate(ArrayList<Character> list ,char op){
27 if(op == '&'){
28 if(find(list,'f')){

Callers

nothing calls this directly

Calls 4

evaluateMethod · 0.95
popMethod · 0.80
pushMethod · 0.80
addMethod · 0.45

Tested by

no test coverage detected