Score of Parentheses
s is a balanced parentheses string. Its score follows these rules:
()scores 1.- Two balanced strings written side by side,
AB, scorescore(A) + score(B). - A balanced string inside a pair,
(A), scores2 * score(A).
Return the score of s.
Example 1
s "()()"
returns 2
1 + 1 = 2.
Example 2
s "(()(()))"
returns 6
2 * (1 + 2 * 1) = 6.
Constraints
2 <= len(s) <= 50sis balanced and has only(and)
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.