题解 | 括号匹配深度
括号匹配深度
https://www.nowcoder.com/practice/a2d5b1875bb0408384278f40d1f236c9
#include <bits/stdc++.h>
using namespace std;
int main(){
//(((())()((()))))()
string s;cin>>s;
stack <char> st;
int ans=0;
for(auto c:s){
if(c=='('){
st.push('(');
}
else{
ans=max( ans , (int)(st.size()) );
st.pop();
}
}
cout<<ans<<'\n';
return 0;
}

查看8道真题和解析