Share my java solution with fake-hashmap


  • 0
    C
    public int longestPalindrome(String s) {
        int length = 0;
        int[] hashMap = new int[58];
        for (int i = 0; i < s.length(); i++) {
    		hashMap[s.charAt(i) - 'A']++;
    	}
        int hasOdd = 0;
        for (int i = 0; i < hashMap.length; i++) {
    		if(hashMap[i] % 2 == 0)
    			length += hashMap[i];
    		else{
    			length += hashMap[i] - 1;
    			hasOdd = 1;
    		}
    	}
        return length + hasOdd;
    }

Log in to reply
 

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