0ms O(N) space JAVA solution


  • -1
    L
    public boolean canPermutePalindrome(String s) {
            
            int len = s.length(), idx=0, odd_count=0;
            char[] char_arry= s.toCharArray(), char_count = new char[256];
            
            for(idx=0;idx<len;idx++){
                
                char_count[(int)char_arry[idx]]++;
                
                if(char_count[(int)char_arry[idx]]%2==0){
                    odd_count--;
                }else{
                    odd_count++;
                }
                
            }
            
            if(odd_count<=1){
                return true;
            }else{
                return false;
            }
        
        }

Log in to reply
 

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