count by array


  • 0
    X
    public boolean canPermutePalindrome(String s) {
        int[] occurs = new int[128];
        for (int i = 0, len = s.length(); i < len; i++) {
            char ch = s.charAt(i);
            occurs[ch] ^= 1;
        }
        return IntStream.of(occurs).sum() <= 1;
    }
    

Log in to reply
 

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