3-line Java functional (declarative) solution


  • 1
    A

    It's super slow, but can you beat the line count? :D

    public boolean canPermutePalindrome(String s) {
        Set<Integer> set = new HashSet<>();
        s.chars().forEach(c -> {if (set.contains(c)) set.remove(c); else set.add(c);});
        return set.size() <= 1;
    }

Log in to reply
 

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