Assuming the string is binary If any two consecutive characters are equal then the string is invalid
for ( int i = 1 ; i < len ; i ++ ) { if ( str . charAt ( i ) == str . charAt ( i - 1 ) ) return false ; }