|
| 1 | +/** |
| 2 | + * [2267] Check if There Is a Valid Parentheses String Path |
| 3 | + * |
| 4 | + * A parentheses string is a non-empty string consisting only of '(' and ')'. It is valid if any of the following conditions is true: |
| 5 | + * |
| 6 | + * It is (). |
| 7 | + * It can be written as AB (A concatenated with B), where A and B are valid parentheses strings. |
| 8 | + * It can be written as (A), where A is a valid parentheses string. |
| 9 | + * |
| 10 | + * You are given an m x n matrix of parentheses grid. A valid parentheses string path in the grid is a path satisfying all of the following conditions: |
| 11 | + * |
| 12 | + * The path starts from the upper left cell (0, 0). |
| 13 | + * The path ends at the bottom-right cell (m - 1, n - 1). |
| 14 | + * The path only ever moves down or right. |
| 15 | + * The resulting parentheses string formed by the path is valid. |
| 16 | + * |
| 17 | + * Return true if there exists a valid parentheses string path in the grid. Otherwise, return false. |
| 18 | + * |
| 19 | + * Example 1: |
| 20 | + * <img alt="" src="https://assets.leetcode.com/uploads/2022/03/15/example1drawio.png" style="width: 521px; height: 300px;" /> |
| 21 | + * Input: grid = [["(","(","("],[")","(",")"],["(","(",")"],["(","(",")"]] |
| 22 | + * Output: true |
| 23 | + * Explanation: The above diagram shows two possible paths that form valid parentheses strings. |
| 24 | + * The first path shown results in the valid parentheses string "()(())". |
| 25 | + * The second path shown results in the valid parentheses string "((()))". |
| 26 | + * Note that there may be other valid parentheses string paths. |
| 27 | + * |
| 28 | + * Example 2: |
| 29 | + * <img alt="" src="https://assets.leetcode.com/uploads/2022/03/15/example2drawio.png" style="width: 165px; height: 165px;" /> |
| 30 | + * Input: grid = [[")",")"],["(","("]] |
| 31 | + * Output: false |
| 32 | + * Explanation: The two possible paths form the parentheses strings "))(" and ")((". Since neither of them are valid parentheses strings, we return false. |
| 33 | + * |
| 34 | + * |
| 35 | + * Constraints: |
| 36 | + * |
| 37 | + * m == grid.length |
| 38 | + * n == grid[i].length |
| 39 | + * 1 <= m, n <= 100 |
| 40 | + * grid[i][j] is either '(' or ')'. |
| 41 | + * |
| 42 | + */ |
| 43 | +pub struct Solution {} |
| 44 | + |
| 45 | +// problem: https://leetcode.com/problems/check-if-there-is-a-valid-parentheses-string-path/ |
| 46 | +// discuss: https://leetcode.com/problems/check-if-there-is-a-valid-parentheses-string-path/discuss/?currentPage=1&orderBy=most_votes&query= |
| 47 | + |
| 48 | +// submission codes start here |
| 49 | + |
| 50 | +impl Solution { |
| 51 | + pub fn has_valid_path(grid: Vec<Vec<char>>) -> bool { |
| 52 | + false |
| 53 | + } |
| 54 | +} |
| 55 | + |
| 56 | +// submission codes end |
| 57 | + |
| 58 | +#[cfg(test)] |
| 59 | +mod tests { |
| 60 | + use super::*; |
| 61 | + |
| 62 | + #[test] |
| 63 | + #[ignore] |
| 64 | + fn test_2267_example_1() { |
| 65 | + let grid = vec![ |
| 66 | + vec!['(', '(', '('], |
| 67 | + vec![')', '(', ')'], |
| 68 | + vec!['(', '(', ')'], |
| 69 | + vec!['(', '(', ')'], |
| 70 | + ]; |
| 71 | + |
| 72 | + let result = true; |
| 73 | + |
| 74 | + assert_eq!(Solution::has_valid_path(grid), result); |
| 75 | + } |
| 76 | + |
| 77 | + #[test] |
| 78 | + #[ignore] |
| 79 | + fn test_2267_example_2() { |
| 80 | + let grid = vec![vec![')', ')'], vec!['(', '(']]; |
| 81 | + |
| 82 | + let result = false; |
| 83 | + |
| 84 | + assert_eq!(Solution::has_valid_path(grid), result); |
| 85 | + } |
| 86 | +} |
0 commit comments