File tree Expand file tree Collapse file tree 1 file changed +31
-0
lines changed Expand file tree Collapse file tree 1 file changed +31
-0
lines changed Original file line number Diff line number Diff line change
1
+ # Given a string which consists of lowercase or uppercase letters, find the
2
+ # length of the longest palindromes that can be built with those letters.
3
+ #
4
+ # This is case sensitive, for example "Aa" is not considered a palindrome here.
5
+ #
6
+ # Note:
7
+ # Assume the length of given string will not exceed 1,010.
8
+ #
9
+ # Example:
10
+ #
11
+ # Input:
12
+ # "abccccdd"
13
+ #
14
+ # Output:
15
+ # 7
16
+ #
17
+ # Explanation:
18
+ # One longest palindrome that can be built is "dccaccd", whose length is 7.
19
+
20
+ import collections
21
+
22
+
23
+ class Solution :
24
+ def longestPalindrome (self , s ):
25
+ dict = collections .Counter (s )
26
+ ans = 0
27
+ for value in dict .values ():
28
+ ans += value // 2 * 2
29
+ if ans % 2 == 0 and value % 2 == 1 :
30
+ ans += 1
31
+ return ans
You can’t perform that action at this time.
0 commit comments