java 6 lines with boolean[]


  • 4
    S
    public boolean canPermutePalindrome(String s) {
        boolean[] map = new boolean[256];
        int count = 0;
        for (char c : s.toCharArray()) {
            count += map[c] ? -1 : 1;
            map[c] = !map[c];
        }
        return count <= 1;
    }

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.