Leetcode - Palindrome Permutation

My code:

public class Solution {
    public boolean canPermutePalindrome(String s) {
        if (s == null || s.length() == 0) {
            return true;
        }
        
        HashMap map = new HashMap();
        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

你可能感兴趣的:(Leetcode - Palindrome Permutation)