Tap here to switch tabs
Problem
Submissions

Problem: Score of Parentheses

med
30 min
Try to solve the Score of Parentheses problem.

Statement

Given a balanced parentheses string s, compute and return the total score of the string based on the following rules:

  • A single pair () has a score of 11.

  • The concatenation of two balanced substrings AB has a score of the score of A plus the score of B.

  • A balanced substring enclosed in parentheses (A) has a score of 22 multiplied by the score of A.

Constraints:

  • 2≤2 \leq s.length ≤50\leq 50

  • s consists of only '(' and ')'.

  • s is a balanced parentheses string.

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Score of Parentheses

med
30 min
Try to solve the Score of Parentheses problem.

Statement

Given a balanced parentheses string s, compute and return the total score of the string based on the following rules:

  • A single pair () has a score of 11.

  • The concatenation of two balanced substrings AB has a score of the score of A plus the score of B.

  • A balanced substring enclosed in parentheses (A) has a score of 22 multiplied by the score of A.

Constraints:

  • 2≤2 \leq s.length ≤50\leq 50

  • s consists of only '(' and ')'.

  • s is a balanced parentheses string.