0
点赞
收藏
分享

微信扫一扫

9.1写论文

晚安大世界 2024-09-02 阅读 6
算法
class Solution {
public:
    bool isValid(string s) {
    int len = s.size();
    stack<char>st;
    st.push('#');
    for(int i = 0; i < len; i++)
    {
        if ((s[i] == ')' && st.top() == '(')||(s[i] == ']' && st.top() == '[') ||(s[i] == '}' && st.top() == '{'))
         st.pop();
         else
         {
            st.push(s[i]);
         }
    }
    return st.top() == '#';
    }
};
举报

相关推荐

0 条评论