Z25
Score of Parentheses
Problem Statement & Objective
Given a balanced parentheses string s, return the score of the string based on nesting rules: () has score 1, AB has score A + B, and (A) has score 2 * A.
Function Signature (Python)
score_of_parentheses(s: str) -> intInput & Output Contract
Output Rule:Hesaplanan skor tam sayısı.
System Constraints
2 <= s.length <= 50
s dengeli parantez metnidirExample Execution Walkthrough
s = '(()(()))' -> ( 1 + (1) ) = ( 1 + 2 ) = (3) = 6Example Test Scenarios (3)
Example 1
Input:
["()"]Expected Output:
1Example 2: 2 * 1
Input:
["(())"]Expected Output:
2Example 3: 1 + 1
Input:
["()()"]Expected Output:
2