fork(1) download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. String input = "7888885466662716666";
  13. addToList(input);
  14. }
  15. public static void addToList(String input) {
  16. String temp;
  17. List<String> l = new ArrayList<>();
  18. for (int i = 0; i < input.length() - 1; i++) {
  19. if (input.charAt(i) == input.charAt(i + 1)) {
  20. temp = String.valueOf(input.charAt(i));
  21. for (int j = i; j < input.length() - 1; j++) {
  22. if (input.charAt(j) == input.charAt(j + 1)) {
  23. temp += String.valueOf(input.charAt(j + 1));
  24. if (j == input.length() - 2) {
  25. i = j;
  26. if (!temp.isEmpty()) {
  27. l.add(temp);
  28. }
  29. break;
  30. }
  31. } else {
  32. i = j - 1;
  33. if (!temp.isEmpty()) {
  34. l.add(temp);
  35. }
  36. break;
  37. }
  38. }
  39. }
  40. }
  41. System.out.println(getHighestOccurences(l));
  42. }
  43.  
  44. public static String getHighestOccurences(List<String> list) {
  45. int max = 0;
  46. int curr;
  47. String currKey = null;
  48. Set<String> unique = new HashSet<>(list);
  49. for (String key : unique) {
  50. curr = Collections.frequency(list, key);
  51. if (max < curr) {
  52. max = curr;
  53. currKey = key;
  54. }
  55. }
  56. return currKey;
  57. }
  58. }
Success #stdin #stdout 0.08s 2184192KB
stdin
Standard input is empty
stdout
6666