fix EmptyStackException
This commit is contained in:
parent
87ed040b3b
commit
dff1b0931c
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user