604. Score of Parentheses

EasyStackStackString

Given a balanced parentheses string s, compute its score by the rules: '()' scores 1; 'AB' scores A+B for adjacent balanced parts; '(A)' scores 2*A. Return the total score. The input is JSON {s}.

Input: JSON {s}.

Output: Integer — the score.

Examples

Example 1
Input: {"s":"()"}
Output: 1
Explanation: A single pair.
Example 2
Input: {"s":"(())"}
Output: 2
Explanation: 2 times the inner 1.
Example 3
Input: {"s":"()()"}
Output: 2
Explanation: 1 + 1.

Constraints

Asked by

MetaGoogleBloombergAmazon
Solve this problem in the editor →