passes 19/86 test cases, needs refinement
This commit is contained in:
parent
8280036777
commit
d25d1f862c
21
Top150Interview/856_Score_of_Parenthesis.py
Normal file
21
Top150Interview/856_Score_of_Parenthesis.py
Normal file
@ -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("()"))
|
||||||
Loading…
Reference in New Issue
Block a user