题解 | #括号匹配深度# --栈
括号匹配深度
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")
#每日一题#