loom-benchmark-mbpp / 125 /solution /_reference.py
sqy201x's picture
Add files using upload-large-folder tool
0e69e56 verified
Raw
History Blame Contribute Delete
259 Bytes
def find_length(string):
n = len(string)
current_sum = 0
max_sum = 0
for i in range(n):
current_sum += (1 if string[i] == '0' else -1)
if current_sum < 0:
current_sum = 0
max_sum = max(current_sum, max_sum)
return max_sum if max_sum else 0