Java || 100ms || Easy Approach
\n\n# Approach\n Describe your approach to solving the problem. \n We have to calculate the maximum pair possible from every character.\n Store the occurence of
\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n* We have to calculate the maximum pair possible from every character.\n* Store the occurence of every character in count array.\n* Then iterate over count array, and let occurence of character is n then do,\n* if n is even then add n. (i.e let n = 4 , then we can use all characters in palindrome string).\n* if n is odd then add n - 1.\n* take a boolean variable (one) which keep tracks that is there any extra character present or not. (i.e not as pair)\n* Then at last, if any extra character is present then return len + 1.\n* Else return len.\n\n# Complexity\n- Time complexity: O(N)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(N)\n\n# Code\n```\nclass Solution {\n    public int longestPalindrome(String s) {\n        int[] count = new int[256];\n        for(char ch : s.toCharArray()){\n            count[ch]++;\n        }\n\n        boolean one = false;\n        int len = 0;\n        for(int ele : count){\n            if(ele%2 == 0)\n               len += ele;\n            else{\n                len += ele-1;\n                one = true;\n            }\n        }\n        return one ? len + 1 : len;\n    }\n}\n```
['Java']