Skip to content

Commit ff53d19

Browse files
1614. Maximum Nesting Depth of the Parentheses
Leetcode question solution
1 parent 15edf7a commit ff53d19

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
class Solution {
2+
public int maxDepth(String s) {
3+
Stack<Character> st=new Stack<>();
4+
int count=0;
5+
for(int i=0;i<s.length();i++){
6+
if(s.charAt(i)=='('){
7+
st.push(s.charAt(i));
8+
}
9+
else{
10+
if(count<st.size())
11+
count=st.size();
12+
13+
else if(s.charAt(i)==')'){
14+
st.pop();
15+
}
16+
17+
}
18+
19+
}
20+
return count;
21+
}
22+
}

0 commit comments

Comments
 (0)