856. Score of Parentheses
Practice Score of Parentheses for free on NudgeCode: Medium, Stack pattern. Write it in Python or JavaScript, run the tests in your browser, and ask for a hint when you are stuck.
s is a balanced string of ( and ). Its score is defined recursively:
()scores 1.- Two balanced strings side by side,
AB, scoreA + B. - A balanced string wrapped in a pair,
(A), scores2 * A.
Return the score of s.
Example
s = "()()" -> 2
s = "(()())" -> 4
s = "(()(()))" -> 6
Constraints
- 2 <= s.length <= 50
sis balanced