If adjacent character are same then increase counter
if ( S . charAt ( i ) == S . charAt ( i + 1 ) ) c += 1 ; else { p . add ( c ) ; c = 1 ; } p . add ( c ) ; } if ( p . size ( ) == 1 ) System . out . println ( " Yes " ) ; else System . out . println ( " No " ) ; }