856. Score of Parentheses Medium

@problem@discussion
#String#Stack



1/**
2 * [856] Score of Parentheses
3 *
4 * Given a balanced parentheses string s, return the score of the string.
5 * The score of a balanced parentheses string is based on the following rule:
6 * 
7 * 	"()" has score 1.
8 * 	AB has score A + B, where A and B are balanced parentheses strings.
9 * 	(A) has score 2 * A, where A is a balanced parentheses string.
10 * 
11 *  
12 * Example 1:
13 * 
14 * Input: s = "()"
15 * Output: 1
16 * 
17 * Example 2:
18 * 
19 * Input: s = "(())"
20 * Output: 2
21 * 
22 * Example 3:
23 * 
24 * Input: s = "()()"
25 * Output: 2
26 * 
27 *  
28 * Constraints:
29 * 
30 * 	2 <= s.length <= 50
31 * 	s consists of only '(' and ')'.
32 * 	s is a balanced parentheses string.
33 * 
34 */
35pub struct Solution {}
36
37// problem: https://leetcode.com/problems/score-of-parentheses/
38// discuss: https://leetcode.com/problems/score-of-parentheses/discuss/?currentPage=1&orderBy=most_votes&query=
39
40// submission codes start here
41
42impl Solution {
43    pub fn score_of_parentheses(s: String) -> i32 {
44        0
45    }
46}
47
48// submission codes end
49
50#[cfg(test)]
51mod tests {
52    use super::*;
53
54    #[test]
55    fn test_856() {
56    }
57}
58


Back
© 2025 bowen.ge All Rights Reserved.