Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def get_palindrome(S):
- if S == '9':
- return '11'
- n = len(S)
- S1 = S[:-(n // 2)] + S[:n // 2][::-1]
- if S1 > S:
- return S1
- n1 = (n + 1) // 2
- n2 = n - n1
- N = str(int(S[:n1]) + 1)
- S2 = N + N[:n2][::-1]
- return S2
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement