2384. Largest Palindromic Number
On This Page
class Solution:
def largestPalindromic(self, num: str) -> str:
cnt = Counter(num)
res = ''
for i in range(9, -1, -1):
v = str(i)
if cnt[v] % 2:
res = v
cnt[v] -= 1
break
for i in range(10):
v = str(i)
if cnt[v]:
cnt[v] //= 2
s = cnt[v] * v
res = s + res + s
return res.strip('0') or '0'