题解 | #括号匹配深度# --栈

括号匹配深度

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

#include <iostream>
#include <algorithm>
#include <stack>
using namespace std;

string str;
stack<int> st;
int manL = 0;  // 栈的最大深度就是答案
int main() {
    cin >> str;
    int n = str.size();
    for(int i = 0; i < n; i ++){
        if(str[i] == '('){
            st.push(i);
            manL = max(manL, (int)st.size());
        }else{
            st.pop();
        }
    }
    cout << manL << endl;

    return 0;
}
// 64 位输出请用 printf("%lld")

#每日一题#
全部评论

相关推荐

05-14 20:34
门头沟学院 Java
窝补药贝八股:管他们,乱说,反正又不去,直接说680
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务