1614. Maximum Nesting Depth of the Parentheses Easy
1/**
2 * [1614] Maximum Nesting Depth of the Parentheses
3 *
4 * A string is a valid parentheses string (denoted VPS) if it meets one of the following:
5 *
6 * It is an empty string "", or a single character not equal to "(" or ")",
7 * It can be written as AB (A concatenated with B), where A and B are VPS's, or
8 * It can be written as (A), where A is a VPS.
9 *
10 * We can similarly define the nesting depth depth(S) of any VPS S as follows:
11 *
12 * depth("") = 0
13 * depth(C) = 0, where C is a string with a single character not equal to "(" or ")".
14 * depth(A + B) = max(depth(A), depth(B)), where A and B are VPS's.
15 * depth("(" + A + ")") = 1 + depth(A), where A is a VPS.
16 *
17 * For example, "", "()()", and "()(()())" are VPS's (with nesting depths 0, 1, and 2), and ")(" and "(()" are not VPS's.
18 * Given a VPS represented as string s, return the nesting depth of s.
19 *
20 * Example 1:
21 *
22 * Input: s = "(1+(2*3)+((<u>8</u>)/4))+1"
23 * Output: 3
24 * Explanation: Digit 8 is inside of 3 nested parentheses in the string.
25 *
26 * Example 2:
27 *
28 * Input: s = "(1)+((2))+(((<u>3</u>)))"
29 * Output: 3
30 *
31 *
32 * Constraints:
33 *
34 * 1 <= s.length <= 100
35 * s consists of digits 0-9 and characters '+', '-', '*', '/', '(', and ')'.
36 * It is guaranteed that parentheses expression s is a VPS.
37 *
38 */
39pub struct Solution {}
40
41// problem: https://leetcode.com/problems/maximum-nesting-depth-of-the-parentheses/
42// discuss: https://leetcode.com/problems/maximum-nesting-depth-of-the-parentheses/discuss/?currentPage=1&orderBy=most_votes&query=
43
44// submission codes start here
45
46impl Solution {
47 pub fn max_depth(s: String) -> i32 {
48 0
49 }
50}
51
52// submission codes end
53
54#[cfg(test)]
55mod tests {
56 use super::*;
57
58 #[test]
59 fn test_1614() {
60 }
61}
62
Back
© 2025 bowen.ge All Rights Reserved.