Open yokostan opened 5 years ago
HashMap:
class Solution { public boolean canPermutePalindrome(String s) { if (s == null || s.length() == 0) return false; HashMap<Character, Integer> map = new HashMap<Character, Integer>(); for (int i = 0; i < s.length(); i++) { char c = s.charAt(i); if (!map.containsKey(c)) { map.put(c, 1); } else { map.remove(c); } } return map.size() <= 1; } }
HashMap: