Easy || 100% || Fully Explained || Java || Clean Solution || Using HashSet || O(n)
Java Solution:\n\n// Runtime: 4 ms, faster than 79.44% of Java online submissions for Longest Palindrome.\n// Time Complexity : O(n)\nclass Solution {\n    publ
# **Java Solution:**\n```\n// Runtime: 4 ms, faster than 79.44% of Java online submissions for Longest Palindrome.\n// Time Complexity : O(n)\nclass Solution {\n    public int longestPalindrome(String s) {\n        int length = 0;\n        // Create a HashSet...\n        HashSet<Character> hset = new HashSet<Character>();\n        // Traverse every element through the loop...\n        for (int idx = 0; idx < s.length(); idx++) {\n            // Convert string to character array...\n            char character = s.charAt(idx);\n            // If hset contains character already, emove that character & adding 2 to length...\n            // It means we get pair of character which is used in palindrome...\n            if (hset.contains(character)) {\n                length += 2;\n                hset.remove(character);\n            }\n            // Otherwise, add the character to the hashset...\n            else {\n                hset.add(character);\n            }\n        }\n        // If the size of the set is greater than zero, move length forward...\n        if (hset.size() > 0) {\n            length ++;\n        }\n        return length;      // Return the length of the longest palindrome...\n    }\n}\n```\n**I am working hard for you guys...\nPlease upvote if you found any help with this code...**
['Hash Table', 'String', 'Java']