Java solution using array


  • 0
    F
    public class Solution {
        public boolean canPermutePalindrome(String s) {
            char[] c = new char[256];
            int flag = 0;
            for(int i = 0;i<s.length();i++){
                c[s.charAt(i)]++;
            }
            for(char ch : c){
                if(ch % 2 != 0) flag++;
                if(flag>1) return false;
            }
            return true;
        }
    }
    

Log in to reply
 

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