题解 | #括号匹配深度#

括号匹配深度

https://www.nowcoder.com/practice/a2d5b1875bb0408384278f40d1f236c9

//https://www.nowcoder.com/practice/a2d5b1875bb0408384278f40d1f236c9?tpId=90&tqId=30808&tPage=2&rp=2&ru=%2Fta%2F2018test&qru=%2Fta%2F2018test%2Fquestion-ranking&tab=answerKey

#include <iostream>
#include <stack>
#include <algorithm>

using namespace std;

int main() {
    string s;
    while (cin >> s) {
        stack<char> st;
        int countn = 0;

        for(int i = 0;i<s.size();i++){
            if(s[i]=='(')
                st.push(s[i]);
            else{
                int tem = st.size();
                countn = max(countn, tem);
                st.pop();
            }
        }

        cout << countn << endl;
    }
}

全部评论

相关推荐

点赞 评论 收藏
分享
找只鸡:可以,直接拉黑这个邮箱
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务