My code:
public class Solution {
public boolean canPermutePalindrome(String s) {
if (s == null || s.length() == 0) {
return true;
}
HashMap<Character, Integer> map = new HashMap<Character, Integer>();
for (int i = 0; i < s.length(); i++) {
char curr = s.charAt(i);
if (!map.containsKey(curr)) {
map.put(curr, 1);
}
else {
map.put(curr, map.get(curr) + 1);
}
}
int oddCounter = 0;
for (Character c : map.keySet()) {
int curr = map.get(c);
if (curr % 2 == 1) {
oddCounter++;
}
if (oddCounter >= 2) {
return false;
}
}
return true;
}
}
简单题,想法很直接。
Anyway, Good luck, Richardo! -- 09/19/2016