10 lines simple solution in Java, 1ms.


  • 0
    S
    public class Solution {
        public boolean canPermutePalindrome(String s) {
            int[] counts = new int[256];
            int odd = 0;
            for(int i=0; i<s.length(); i++){
                char c = s.charAt(i);
                counts[c]++;
                if(counts[c] %2 == 1)
                    odd++;
                else
                    odd--;
            }
            return odd <= 1;
        }
    }

  • 0
    X
    char c = s.charAt(i);
    counts[c]++;    
    

    why can we store char type in Int[ ] array?


  • 2
    Y
    This post is deleted!

Log in to reply
 

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