[LeetCode] Score of Parentheses 括号的分数

Posted grandyang

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了[LeetCode] Score of Parentheses 括号的分数相关的知识,希望对你有一定的参考价值。



Given a balanced parentheses string?S, compute the score of the string based on the following rule:

  • ()?has score 1
  • AB?has score?A + B, where A and B are balanced parentheses strings.
  • (A)?has score?2 * A, where A is a balanced parentheses string.

Example 1:

Input: "()"
Output: 1

Example 2:

Input: "(())"
Output: 2

Example 3:

Input: "()()"
Output: 2

Example 4:

Input: "(()(()))"
Output: 6

Note:

  1. S?is a balanced parentheses string, containing only?(?and?).
  2. 2 <= S.length <= 50



参考资料:

https://leetcode.com/problems/score-of-parentheses/

以上是关于[LeetCode] Score of Parentheses 括号的分数的主要内容,如果未能解决你的问题,请参考以下文章

[LeetCode] Score of Parentheses 括号的分数

leetcode1301. Number of Paths with Max Score

leetcode1039. Minimum Score Triangulation of Polygon

Leetcode 856. Score of Parentheses 括号得分(栈)

leetcode 856. 括号的分数(Score of Parentheses)

Leetcode-5047 Minimum Score Triangulation of Polygon(多边形三角剖分的最低得分)