Skip to content

Commit 7989bc5

Browse files
authored
Merge pull request #3540 from aadil42/patch-81
Create 1614-maximum-nesting-depth-of-the-parentheses.js
2 parents 912f676 + 26c1487 commit 7989bc5

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/**
2+
* Stack
3+
* Time O(n) | Space O(1)
4+
* https://leetcode.com/problems/maximum-nesting-depth-of-the-parentheses
5+
* @param {string} s
6+
* @return {number}
7+
*/
8+
var maxDepth = function(s) {
9+
let currDepth = 0;
10+
let maxDepth = 0;
11+
for (let i = 0; i < s.length; i++) {
12+
if (s[i] === "(") currDepth++;
13+
maxDepth = Math.max(currDepth, maxDepth);
14+
if (s[i] === ")") currDepth--;
15+
}
16+
return maxDepth;
17+
};

0 commit comments

Comments
 (0)