1807. Evaluate the Bracket Pairs of a String Medium

@problem@discussion
#Array#Hash Table#String



1/**
2 * [1807] Evaluate the Bracket Pairs of a String
3 *
4 * You are given a string s that contains some bracket pairs, with each pair containing a non-empty key.
5 * 
6 * 	For example, in the string "(name)is(age)yearsold", there are two bracket pairs that contain the keys "name" and "age".
7 * 
8 * You know the values of a wide range of keys. This is represented by a 2D string array knowledge where each knowledge[i] = [keyi, valuei] indicates that key keyi has a value of valuei.
9 * You are tasked to evaluate all of the bracket pairs. When you evaluate a bracket pair that contains some key keyi, you will:
10 * 
11 * 	Replace keyi and the bracket pair with the key's corresponding valuei.
12 * 	If you do not know the value of the key, you will replace keyi and the bracket pair with a question mark "?" (without the quotation marks).
13 * 
14 * Each key will appear at most once in your knowledge. There will not be any nested brackets in s.
15 * Return the resulting string after evaluating all of the bracket pairs.
16 *  
17 * Example 1:
18 * 
19 * Input: s = "(name)is(age)yearsold", knowledge = [["name","bob"],["age","two"]]
20 * Output: "bobistwoyearsold"
21 * Explanation:
22 * The key "name" has a value of "bob", so replace "(name)" with "bob".
23 * The key "age" has a value of "two", so replace "(age)" with "two".
24 * 
25 * Example 2:
26 * 
27 * Input: s = "hi(name)", knowledge = [["a","b"]]
28 * Output: "hi?"
29 * Explanation: As you do not know the value of the key "name", replace "(name)" with "?".
30 * 
31 * Example 3:
32 * 
33 * Input: s = "(a)(a)(a)aaa", knowledge = [["a","yes"]]
34 * Output: "yesyesyesaaa"
35 * Explanation: The same key can appear multiple times.
36 * The key "a" has a value of "yes", so replace all occurrences of "(a)" with "yes".
37 * Notice that the "a"s not in a bracket pair are not evaluated.
38 * 
39 *  
40 * Constraints:
41 * 
42 * 	1 <= s.length <= 10^5
43 * 	0 <= knowledge.length <= 10^5
44 * 	knowledge[i].length == 2
45 * 	1 <= keyi.length, valuei.length <= 10
46 * 	s consists of lowercase English letters and round brackets '(' and ')'.
47 * 	Every open bracket '(' in s will have a corresponding close bracket ')'.
48 * 	The key in each bracket pair of s will be non-empty.
49 * 	There will not be any nested bracket pairs in s.
50 * 	keyi and valuei consist of lowercase English letters.
51 * 	Each keyi in knowledge is unique.
52 * 
53 */
54pub struct Solution {}
55
56// problem: https://leetcode.com/problems/evaluate-the-bracket-pairs-of-a-string/
57// discuss: https://leetcode.com/problems/evaluate-the-bracket-pairs-of-a-string/discuss/?currentPage=1&orderBy=most_votes&query=
58
59// submission codes start here
60
61impl Solution {
62    pub fn evaluate(s: String, knowledge: Vec<Vec<String>>) -> String {
63        String::new()
64    }
65}
66
67// submission codes end
68
69#[cfg(test)]
70mod tests {
71    use super::*;
72
73    #[test]
74    fn test_1807() {
75    }
76}
77


Back
© 2025 bowen.ge All Rights Reserved.