Simple Java solution using HashSet.


  • 0
    V
    class Solution {
        public boolean canPermutePalindrome(String s) 
        {
        		HashSet<Character> set = new HashSet<Character>();
        		
        		for (int i = 0; i<s.length();i++)
        		{
        			if (set.contains(s.charAt(i)))
        			{
        				set.remove(s.charAt(i));
        				
        			}
        			else
        			{
        				set.add(s.charAt(i));
        			}
        		}
           
        		if (set.size() <=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.