Skip to content

Commit a7b43ab

Browse files
authored
Create 1614-maximum-nesting-depth-of-the-parentheses.js
1 parent 65de835 commit a7b43ab

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/**
2+
* @param {string} s
3+
* @return {number}
4+
*/
5+
const maxDepth = function(s) {
6+
const stack = []
7+
let res = 0
8+
for(let i = 0, len = s.length; i < len; i++) {
9+
if(s[i] === '(') {
10+
stack.push('(')
11+
res = Math.max(res, stack.length)
12+
} else if(s[i] === ')') {
13+
stack.pop()
14+
}
15+
}
16+
17+
return res
18+
};

0 commit comments

Comments
 (0)