SOLUTION INFO
C++ · main.cpp
class Solution {
public:
int longestValidParentheses(string s) {
int N = (int)s.size();
stack<int> st; st.push(-1);
int mx = 0;
for(int i = 0; i < N; ++i) {
char ch = s[i];
if(st.top() != -1 && s[st.top()] == '(' && ch == ')') {
st.pop(), mx = max(mx, i - st.top());
}
else st.push(i);
}
return mx;
}
};
SOLUTION DESCRIPTION
풀이 설명
등록된 풀이 설명이 없습니다.