Java solution:
public static String f(String s) {
int len = s.length();
if (len < 3) return null;
int[] buf = new int[256*256*256];
int cur = (s.charAt(0) << 8) | s.charAt(1);
for (int i = 2; i < len; ++i)
++buf[cur = ((cur & ((1 << 16) - 1)) << 8) |
s.charAt(i)];
int bestCount = Integer.MIN_VALUE;
int best = -1;
for (int i = 0; i < 256*256*256; ++i)
if (bestCount < buf[i]) {
bestCount = buf[i];
best = i;
}
return "" + (char)(best >> 16) + (char)(best >> 8 & 255) +
(char)(best & 255);
}
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Algorithm Geeks" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/algogeeks
-~----------~----~----~----~------~----~------~--~---