Skip to content

Commit 3697c23

Browse files
solves maximum nesting depth of the parentheses
1 parent 8add174 commit 3697c23

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,3 +400,4 @@
400400
| 1592 | [Rearrange Spaces Between Words](https://leetcode.com/problems/rearrange-spaces-between-words) | [![Java](assets/java.png)](src/RearrangeSpacesBetweenWords.java) | |
401401
| 1598 | [Crawler Log Folder](https://leetcode.com/problems/crawler-log-folder) | [![Java](assets/java.png)](src/CrawlerLogFolder.java) | |
402402
| 1603 | [Design Parking System](https://leetcode.com/problems/design-parking-system) | [![Java](assets/java.png)](src/DesignParkingSystem.java) | |
403+
| 1614 | [Maximum Nesting Depth of the Parentheses](https://leetcode.com/problems/maximum-nesting-depth-of-the-parentheses) | [![Java](assets/java.png)](src/MaximumNestingDepthOfTheParentheses.java) | |
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
public class MaximumNestingDepthOfTheParentheses {
2+
public int maxDepth(String s) {
3+
int nestingDepth = 0, maximumNestingDepth = 0;
4+
for (int index = 0 ; index < s.length() ; index++) {
5+
if (s.charAt(index) == '(') nestingDepth++;
6+
else if (s.charAt(index) == ')') nestingDepth--;
7+
maximumNestingDepth = Math.max(nestingDepth, maximumNestingDepth);
8+
}
9+
return maximumNestingDepth;
10+
}
11+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
public class SpecialArrayWithXElementsGreaterThanEqualToX {
2+
public int specialArray(int[] array) {
3+
4+
}
5+
}

0 commit comments

Comments
 (0)