Minimum number of deletions so that no two consecutive are same | Java code to count minimum deletions required so that there are no consecutive characters left ; Function for counting deletions ; If two consecutive characters are the same , delete one of them . ; Driver code ; Function call to print answer
import java . util . * ; class GFG { static int countDeletions ( String s ) { int ans = 0 ; char [ ] str = s . toCharArray ( ) ; for ( int i = 0 ; i < str . length - 1 ; i ++ ) if ( str [ i ] == str [ i + 1 ] ) ans ++ ; return ans ; } public static void main ( String [ ] args ) { String str = " AAABBB " ; System . out . println ( countDeletions ( str ) ) ; } }