Skip to content

Instantly share code, notes, and snippets.

@IngeFrodo
Created August 14, 2020 17:45
Show Gist options
  • Save IngeFrodo/8f561522d8a8ece2253fad00a41071bf to your computer and use it in GitHub Desktop.
Save IngeFrodo/8f561522d8a8ece2253fad00a41071bf to your computer and use it in GitHub Desktop.
class LongestPalindrome {
public int longestPalindrome(String s) {
int[] count = new int[128];
for (char c : s.toCharArray()) {
count[c]++;
}
int odds = 0;
for (char c = 'A'; c <= 'z'; c++) {
if (count[c] % 2 == 1) {
odds++;
}
}
return odds > 1 ? s.length() - odds + 1: s.length();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment