您的位置:首页 > 其它

Palindrome Permutation

2016-07-24 04:47 246 查看
public class Solution {
public boolean canPermutePalindrome(String s) {
if (s == null || s.length() < 2) {
return true;
}
Map<Character, Boolean> map = new HashMap<>();
int oddCount = 0;
for (int i = 0; i < s.length(); i++) {
char c = s.charAt(i);
if (!map.containsKey(c)) {
map.put(c, false);
oddCount++;
} else {
if (map.get(c)) {
map.put(c, false);
oddCount++;
} else {
map.put(c, true);
oddCount--;
}
}
}
boolean evenStr = s.length() % 2 == 0;
if (evenStr) {
if (oddCount == 0) {
return true;
} else {
return false;
}
} else {
if (oddCount == 1) {
return true;
} else {
return false;
}
}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: