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

括号匹配深度

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

#每日一题#
全部评论

相关推荐

KPLACE:首先是板面看起来不够,有很多奖,比我厉害。项目要精减,大概详细描述两到三个,要把技术栈写清楚,分点,什么算法,什么外设,怎么优化,不要写一大堆,分点,你写上去的目的,一是让别人知道你做了这个知识点,然后在面试官技术面的时侯,他知道你会这个,那么就会跟你深挖这个,然后就是个人评价改为专业技能
点赞 评论 收藏
分享
黑皮白袜臭脚体育生:简历条例统一按使用了什么技术实现了什么功能解决了问题或提升了什么性能指标来写会好些,如使用布隆过滤器实现了判断短链接是否存在,大大提升了查询速度
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务