File tree Expand file tree Collapse file tree 1 file changed +0
-14
lines changed
src/main/java/g1101_1200/s1106_parsing_a_boolean_expression Expand file tree Collapse file tree 1 file changed +0
-14
lines changed Original file line number Diff line number Diff line change @@ -12,13 +12,11 @@ public class Solution {
1212 public boolean parseBoolExpr (String expression ) {
1313 this .source = expression ;
1414 this .index = 0 ;
15-
1615 return expr ();
1716 }
1817
1918 private boolean expr () {
2019 boolean res = false ;
21-
2220 if (match ('!' )) {
2321 res = not ();
2422 } else if (match ('&' )) {
@@ -28,52 +26,42 @@ private boolean expr() {
2826 } else {
2927 res = bool ();
3028 }
31-
3229 return res ;
3330 }
3431
3532 private boolean not () {
3633 consume ('!' , "Expect '!'" );
37-
3834 return !group ().get (0 );
3935 }
4036
4137 private boolean or () {
4238 consume ('|' , "Expect '|'" );
43-
4439 boolean res = false ;
4540 for (boolean e : group ()) {
4641 res |= e ;
4742 }
48-
4943 return res ;
5044 }
5145
5246 private boolean and () {
5347 consume ('&' , "Expect '&'" );
54-
5548 boolean res = true ;
5649 for (boolean e : group ()) {
5750 res &= e ;
5851 }
59-
6052 return res ;
6153 }
6254
6355 private List <Boolean > group () {
6456 consume ('(' , "Expect '('" );
65-
6657 List <Boolean > res = new ArrayList <>();
6758 while (!match (')' )) {
6859 res .add (expr ());
69-
7060 if (match (',' )) {
7161 advance ();
7262 }
7363 }
74-
7564 consume (')' , "Expect ')'" );
76-
7765 return res ;
7866 }
7967
@@ -91,7 +79,6 @@ private void advance() {
9179 if (isAtEnd ()) {
9280 return ;
9381 }
94-
9582 index ++;
9683 }
9784
@@ -103,7 +90,6 @@ private boolean match(char ch) {
10390 if (isAtEnd ()) {
10491 return false ;
10592 }
106-
10793 return peek () == ch ;
10894 }
10995
You can’t perform that action at this time.
0 commit comments