Find the count of continuous 0's and 1's number
Problem to count the continuous 0's and 1's numbers in given binary string.
Example-1:
Input : n = "11000010001" Output : [2, 4, 1, 3, 1]
Example-2:
Input : n = "10001" Output : [1, 3, 1]
Solution
n = "11000010001" n = n + " " k = 1 l = [] for i in range(1,len(n)): if(n[i-1] == n[i]): k += 1 continue else: l.append(k) k = 1 print(l)
Output
[2, 4, 1, 3, 1]