266. Palindrome Permutation

Given a string, determine if a permutation of the string could form a palindrome.

For example,
"code" -> False, "aab" -> True, "carerac" -> True.

一刷
题解:
词频统计

public class Solution {
    public boolean canPermutePalindrome(String s) {
        int[] freq = new int[26*2];
        for(int i=0; i='a')  freq[ch - 'a']++;
            else if(ch <='Z' && ch>='A')  freq[ch - 'A' + 26]++;
           
        }
        int odd = 0;
        for(int i=0; i

或者用set,应该更快

二刷
sort

class Solution {
    public boolean canPermutePalindrome(String s) {
        char[] arr = s.toCharArray();
        Arrays.sort(arr);
        int pos = 0;
        boolean count = false;
        while(pos

你可能感兴趣的:(266. Palindrome Permutation)