Simple java solution with hashtable


  • 0
    S
    public class Solution {
        public boolean canPermutePalindrome(String s) {
            int[] htable = new int[256];
            for(int i=0; i<s.length(); i++) {
                htable[s.charAt(i)] += 1;
            }
            int count_odd = 0;
            for(int each : htable){
                if(each % 2 == 1) count_odd+=1;
                if(count_odd > 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.