[leetcode, JS] 1614. Maximum Nesting Depth of the Parentheses

mxxn·2023년 10월 27일
0

leetcode

목록 보기
106/198

문제

문제 링크 : Maximum Nesting Depth of the Parentheses

풀이

/**
 * @param {string} s
 * @return {number}
 */
var maxDepth = function(s) {
    let maxCount = 0;
    let openCount = 0;
    for (let i = 0; i < s.length; i++) {
        if (s[i] === "(") maxCount = Math.max(maxCount, ++openCount);
        else if (s[i] === ")") openCount--;
    }
    return maxCount;
};
  1. '('가 가장 많이 있는 숫자의 '(' 개수를 구하는 풀이
  • Runtime 57ms, Memory 41.52MB
profile
내일도 글쓰기

0개의 댓글