Maximum Nesting Depth of the Parentheses LeetCode solution in Java
1class Solution {2public int maxDepth(String s) {3int count = 0; // count current dept of "()"4int max = 0; // count max dept of "()"56for (int i = 0; i < s.length(); i++) {7if (s.charAt(i) == '(') {8count++;9} else if (s.charAt(i) == ')') {10count--;11}12max = Math.max(count, max);13}14return max;15}16}