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); 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;