1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | public class Solution { public boolean canPermutePalindrome(String s) { HashMap<Character, Integer> lookup = new HashMap<Character, Integer>(); for (int i = 0; i < s.length(); i++){ char key = s.charAt(i); int count = 1; if (lookup.containsKey(key)){ count = lookup.get(key)-1; } if (count == 0){ lookup.remove(key); }else{ lookup.put(key, count); } } return lookup.size() <= 1; } } |
No comments:
Post a Comment