Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class GFG {
- static void maxRepeating(String str)
- {
- int len = str.length();
- int count = 0;
- int max = -1;
- char c = '-';
- int temp[] = new int[str.length()];
- for(int i = 0; i < str.length(); i++) {
- temp[i] = 1;
- }
- for (int i=1; i<len; i++)
- {
- if(str.charAt(i) == str.charAt(i-1)) {
- temp[i] = temp[i-1] + 1;
- if( temp[i] > max){
- max = temp[i];
- c = str.charAt(i);
- }
- }
- }
- System.out.println(c + " : " + c + " count= " + max);
- // for(int i = 0; i < str.length(); i++) {
- // System.out.println( str.charAt(i) + " : " + temp[i]);
- // }
- // System.out.println(" ");
- }
- public static void main(String args[])
- {
- String str = "aabcddbbbea";
- maxRepeating(str);
- }
- }
Add Comment
Please, Sign In to add comment