Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution:
- def longestPalindrome(self, s: str) -> int:
- dict={}
- for i in s:
- dict[i]=dict.get(i,0)+1
- ans=0
- for k,v in dict.items():
- if v%2==1:
- if ans%2==0: #atleast one character can be kept in centre
- ans+=v
- else:
- ans+=v-1
- else:
- ans+=v
- return ans
Advertisement
Add Comment
Please, Sign In to add comment