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

括号匹配深度

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

#每日一题#
全部评论

相关推荐

纯真的河老师在喝茶:第一个是这个时间点岗位少,第二个是这个简历重复度太高了,10个有9个简历差不多的
点赞 评论 收藏
分享
10-31 13:04
南华大学 Java
嵌入式的小白:很多面试,面试前不会去打扰cto的,但一般cto不会在这些小事上刷人,只能说这个cto比较操心,啥重要不重要,紧急不紧急的,估计都会过问,平淡看待吧
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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