描述
Given a balanced parentheses string S
, compute the score of the string based on the following rule:
()
has score 1AB
has scoreA + B
, where A and B are balanced parentheses strings.(A)
has score2 * A
, where A is a balanced parentheses string.
Example 1:
1 | Input: "()" |
Example 2:
1 | Input: "(())" |
Example 3:
1 | Input: "()()" |
Example 4:
1 | Input: "(()(()))" |
分析
类似于 921. Minimum Add to Make Parentheses Valid 这道题,只不过这道题需要根据定义进行计算。
解决方案1(Java)
1 | class Solution { |