Skip to content

Latest commit

 

History

History
26 lines (22 loc) · 562 Bytes

Question_1614.md

File metadata and controls

26 lines (22 loc) · 562 Bytes

LeetCode Records - Question 1614 Maximum Nesting Depth of the Parentheses

Attempt 1: Use two variables

class Solution {
    public int maxDepth(String s) {
        int max = 0;
        int curr = 0;

        for (char ch : s.toCharArray()) {
            if (ch == '(') {
                curr++;
                max = Math.max(curr, max);
            } else if (ch == ')') {
                curr--;
            }
        }

        return max;
    }
}
  • Runtime: 0 ms (Beats: 100.00%)
  • Memory: 41.98 MB (Beats: 6.76%)