fork 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.  
  11. public static int find(ArrayList<String> words) {
  12. int size = 1;
  13. int total = 0;
  14. for(String w : words) {
  15.  
  16. for(int i = 0; i < w.length() - 1; i++) {
  17. int front = 1, back = 1;
  18. while(((i - back >= 0) && (i + front <= w.length() - 1) && (w.charAt(i + front) == w.charAt(i - back)))) {
  19. size += 2;
  20. back++;
  21. front++;
  22. }
  23. if (size > total) {
  24. total = size;
  25. }
  26. size = 1;
  27. }
  28. }
  29. return total;
  30. }
  31.  
  32.  
  33. public static void main (String[] args) throws java.lang.Exception
  34. {
  35. ArrayList l = new ArrayList();
  36. l.add("abba");
  37. System.out.println(find(l));
  38. }
  39. }
Success #stdin #stdout 0.04s 4386816KB
stdin
Standard input is empty
stdout
1