题解 | #括号匹配深度#
括号匹配深度
https://www.nowcoder.com/practice/a2d5b1875bb0408384278f40d1f236c9
import java.util.*; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); while (scanner.hasNext()) { String s = scanner.nextLine(); maxDepthOfSignal(s); } } private static void maxDepthOfSignal(String s) { char[] chars = s.toCharArray(); Stack<Character> stack = new Stack<>(); int max = 0; for (char ch : chars) { if (ch == '(') { stack.push(')'); } else if (ch == ')') { max = Math.max(stack.size(), max); stack.pop(); } } System.out.println(max); } }