From d25d1f862ce818512eec5d3622693873f99b769b Mon Sep 17 00:00:00 2001 From: ImAlpha Date: Sat, 22 Jul 2023 18:20:23 -0700 Subject: [PATCH] passes 19/86 test cases, needs refinement --- Top150Interview/856_Score_of_Parenthesis.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 Top150Interview/856_Score_of_Parenthesis.py diff --git a/Top150Interview/856_Score_of_Parenthesis.py b/Top150Interview/856_Score_of_Parenthesis.py new file mode 100644 index 0000000..6cb322a --- /dev/null +++ b/Top150Interview/856_Score_of_Parenthesis.py @@ -0,0 +1,21 @@ +def scoreOfParentheses(s): + """ + :type s: str + :rtype: int + """ + score = left = right = 0 + + for x in s: + if x == "(": + left += 1 + score += 1 + elif x == ")": + right += 1 + score += 1 + if left > right: + score = 2 * left + else: + score /= 2 + return score + +print(scoreOfParentheses("()"))