Deletions of "01" or "10" in binary string to make it free from "01" or "10" | Java implementation of the approach ; Function to return the count of deletions of sub - strings "01" or "10" ; To store the count of 0 s and 1 s ; Driver code
class GFG { static int substrDeletion ( String str , int len ) { int count0 = 0 , count1 = 0 ; for ( int i = 0 ; i < len ; i ++ ) { if ( str . charAt ( i ) == '0' ) count0 ++ ; else count1 ++ ; } return Math . min ( count0 , count1 ) ; } public static void main ( String [ ] args ) { String str = "010" ; int len = str . length ( ) ; System . out . println ( substrDeletion ( str , len ) ) ; } }