#856

Score of Parentheses

specialist · 655 · lc medium +30 · verified · 63.6% accepted · 5,598 likes · top 66%

Description

Given a balanced parentheses string s, compute and return its score under these rules:

- "()" has score 1.

- AB has score A + B, where A and B are balanced parentheses strings placed side by side.

- (A) has score 2 * A, where A is a balanced parentheses string.

Example 1:

Input: s = "()"
Output: 1

Example 2:

Input: s = "(())"
Output: 2

Example 3:

Input: s = "()()"
Output: 2

Code

1
2
3