Skip to content

Latest commit

 

History

History
139 lines (56 loc) · 1.74 KB

File metadata and controls

139 lines (56 loc) · 1.74 KB

中文文档

Description

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

    <li><code>()</code> has score 1</li>
    
    <li><code>AB</code> has score <code>A + B</code>, where A and B are balanced parentheses strings.</li>
    
    <li><code>(A)</code> has score <code>2 * A</code>, where A is a balanced parentheses string.</li>
    

 

Example 1:

Input: "()"

Output: 1

Example 2:

Input: "(())"

Output: 2

Example 3:

Input: "()()"

Output: 2

Example 4:

Input: "(()(()))"

Output: 6

 

Note:

    <li><code>S</code> is a balanced parentheses string, containing only <code>(</code> and <code>)</code>.</li>
    
    <li><code>2 &lt;= S.length &lt;= 50</code></li>
    

Solutions

Python3

Java

...