1's and 0's continuous pattern counting
Problem to count the number of continuous sequence of 0's and 1's.
Example-1:
Input : s = "100my001crazy101coding110" Output : 4
Example-2:
Input : s = "1my5crazy01coding0" Output : 3
Solution
import re s = "100my001crazy101coding110" r = re.findall(r"[0-1]+",s) print(len(r))
Output
4