22 lines
382 B
Python
22 lines
382 B
Python
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("()"))
|