Minimum number of characters to be removed to make a binary string alternate | Java program to find minimum number of characters to be removed to make a string alternate . ; Returns count of minimum characters to be removed to make s alternate . ; if two alternating characters of string are same ; result ++ ; then need to delete a character ; Driver code
import java . io . * ; public class GFG { static int countToMake0lternate ( String s ) { int result = 0 ; for ( int i = 0 ; i < ( s . length ( ) - 1 ) ; i ++ ) if ( s . charAt ( i ) == s . charAt ( i + 1 ) ) return result ; } static public void main ( String [ ] args ) { System . out . println ( countToMake0lternate ( "000111" ) ) ; System . out . println ( countToMake0lternate ( "11111" ) ) ; System . out . println ( countToMake0lternate ( "01010101" ) ) ; } }