summaryrefslogtreecommitdiff
path: root/progs/a488.py
diff options
context:
space:
mode:
Diffstat (limited to 'progs/a488.py')
-rw-r--r--progs/a488.py9
1 files changed, 9 insertions, 0 deletions
diff --git a/progs/a488.py b/progs/a488.py
new file mode 100644
index 0000000..c5865d6
--- /dev/null
+++ b/progs/a488.py
@@ -0,0 +1,9 @@
+def find_length(string, n):
+ 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 \ No newline at end of file