{"id":180,"date":"2018-05-26T21:17:10","date_gmt":"2018-05-26T13:17:10","guid":{"rendered":"https:\/\/www.ccagml.com\/?p=180"},"modified":"2018-11-27T17:17:53","modified_gmt":"2018-11-27T09:17:53","slug":"409-longest-palindrome","status":"publish","type":"post","link":"https:\/\/www.ccagml.com\/?p=180","title":{"rendered":"409. Longest Palindrome"},"content":{"rendered":"<p>Given a string which consists of lowercase or uppercase letters, find the length of the longest palindromes that can be built with those letters.<\/p>\n<p>This is case sensitive, for example\u00a0<code>\"Aa\"<\/code>\u00a0is not considered a palindrome here.<\/p>\n<p><b>Note:<\/b><br \/>\nAssume the length of given string will not exceed 1,010.<\/p>\n<p><b>Example:<\/b><\/p>\n<pre>Input:\r\n\"abccccdd\"\r\n\r\nOutput:\r\n7\r\n\r\nExplanation:\r\nOne longest palindrome that can be built is \"dccaccd\", whose length is 7.<\/pre>\n<p><strong>Python<\/strong><\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\"> \r\nclass Solution:\r\n    def longestPalindrome(self, s):\r\n        &quot;&quot;&quot;\r\n        :type s: str\r\n        :rtype: int\r\n        &quot;&quot;&quot;\r\n        result = 0\r\n        d = dict()\r\n        for i in s:\r\n            if i in d:\r\n                d[i] = d[i] + 1\r\n                if d[i] % 2 == 0:\r\n                    result += 1\r\n            else:\r\n                d[i] = 1\r\n        result *= 2\r\n        if result == 0:\r\n            return 1\r\n        if result != len(s):\r\n            return result + 1\r\n        else:\r\n            return result\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Given a string which consists of lowercase or uppercase<a href=\"https:\/\/www.ccagml.com\/?p=180\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">409. Longest Palindrome<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[29,20],"tags":[],"_links":{"self":[{"href":"https:\/\/www.ccagml.com\/index.php?rest_route=\/wp\/v2\/posts\/180"}],"collection":[{"href":"https:\/\/www.ccagml.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.ccagml.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.ccagml.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.ccagml.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=180"}],"version-history":[{"count":1,"href":"https:\/\/www.ccagml.com\/index.php?rest_route=\/wp\/v2\/posts\/180\/revisions"}],"predecessor-version":[{"id":181,"href":"https:\/\/www.ccagml.com\/index.php?rest_route=\/wp\/v2\/posts\/180\/revisions\/181"}],"wp:attachment":[{"href":"https:\/\/www.ccagml.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=180"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.ccagml.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=180"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.ccagml.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=180"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}