fix EmptyStackException
This commit is contained in:
parent
87ed040b3b
commit
dff1b0931c
@ -38,29 +38,25 @@ class BalancedBrackets {
|
|||||||
bracketsStack.push(x);
|
bracketsStack.push(x);
|
||||||
break;
|
break;
|
||||||
case '}':
|
case '}':
|
||||||
if (bracketsStack.peek() == '{') {
|
if (!bracketsStack.empty() && bracketsStack.pop() == '{') {
|
||||||
bracketsStack.pop();
|
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
case '>':
|
case '>':
|
||||||
if (bracketsStack.peek() == '<') {
|
if (!bracketsStack.empty() && bracketsStack.pop() == '<') {
|
||||||
bracketsStack.pop();
|
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
case ')':
|
case ')':
|
||||||
if (bracketsStack.peek() == '(') {
|
if (!bracketsStack.empty() && bracketsStack.pop() == '(') {
|
||||||
bracketsStack.pop();
|
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
case ']':
|
case ']':
|
||||||
if (bracketsStack.peek() == '[') {
|
if (!bracketsStack.empty() && bracketsStack.pop() == '[') {
|
||||||
bracketsStack.pop();
|
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
|
Loading…
Reference in New Issue
Block a user