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("()"))