Skip to content

Commit 114352a

Browse files
Create max-nesting-depth-parentheses.java
1 parent 8be85f2 commit 114352a

File tree

1 file changed

+20
-0
lines changed

1 file changed

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

0 commit comments

Comments
 (0)