Guest User

Untitled

a guest
Nov 23rd, 2017
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  1. public class GFG {
  2.  
  3. static void maxRepeating(String str)
  4. {
  5. int len = str.length();
  6. int count = 0;
  7. int max = -1;
  8. char c = '-';
  9. int temp[] = new int[str.length()];
  10. for(int i = 0; i < str.length(); i++) {
  11. temp[i] = 1;
  12. }
  13.  
  14. for (int i=1; i<len; i++)
  15. {
  16. if(str.charAt(i) == str.charAt(i-1)) {
  17. temp[i] = temp[i-1] + 1;
  18. if( temp[i] > max){
  19. max = temp[i];
  20. c = str.charAt(i);
  21. }
  22. }
  23. }
  24.  
  25. System.out.println(c + " : " + c + " count= " + max);
  26. // for(int i = 0; i < str.length(); i++) {
  27. // System.out.println( str.charAt(i) + " : " + temp[i]);
  28. // }
  29. // System.out.println(" ");
  30. }
  31.  
  32.  
  33. public static void main(String args[])
  34. {
  35.  
  36. String str = "aabcddbbbea";
  37. maxRepeating(str);
  38. }
  39. }
Add Comment
Please, Sign In to add comment