以下代码判断括号是否匹配,请在横线处填入代码。
bool isBalanced(string s) {
stack<char> st;
for (char c : s) {
if (c == '(' || c == '[' || c == '{') {
st.push(c);
} else {
if (st.empty()) return false; // 无括号匹配
char top = st.top();
st.pop();
if ((c == ')' && top != '(') ||
(c == ']' && top != '[') ||
(c == '}' && top != '{')) {
return false;
}
}
}
return ____________; // 在此处填入代码
}
- A.
true - B.
false - C.
st.empty() - D.
!st.empty()