Skip to content

Commit e2c4e9e

Browse files
committed
4-6-24
1 parent bd8416c commit e2c4e9e

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

Jun-4-24.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
class Solution:
2+
def longestPalindrome(self, s: str) -> int:
3+
d = dict(Counter(s))
4+
cnt,odd = 0,0
5+
l = sorted(d.values(),reverse = True)
6+
for i in l:
7+
if i%2==0:
8+
cnt += i
9+
else:
10+
odd += 1
11+
cnt += i-1
12+
if odd!=0:
13+
return cnt+1
14+
return cnt

0 commit comments

Comments
 (0)