fix EmptyStackException

This commit is contained in:
shellhub 2019-09-25 08:57:42 +08:00
parent 87ed040b3b
commit dff1b0931c

View File

@ -38,29 +38,25 @@ class BalancedBrackets {
bracketsStack.push(x);
break;
case '}':
if (bracketsStack.peek() == '{') {
bracketsStack.pop();
if (!bracketsStack.empty() && bracketsStack.pop() == '{') {
break;
} else {
return false;
}
case '>':
if (bracketsStack.peek() == '<') {
bracketsStack.pop();
if (!bracketsStack.empty() && bracketsStack.pop() == '<') {
break;
} else {
return false;
}
case ')':
if (bracketsStack.peek() == '(') {
bracketsStack.pop();
if (!bracketsStack.empty() && bracketsStack.pop() == '(') {
break;
} else {
return false;
}
case ']':
if (bracketsStack.peek() == '[') {
bracketsStack.pop();
if (!bracketsStack.empty() && bracketsStack.pop() == '[') {
break;
} else {
return false;