Advertisement
Guest User

Untitled

a guest
Nov 18th, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.27 KB | None | 0 0
  1. def get_palindrome(S):
  2.     if S == '9':
  3.         return '11'
  4.     n = len(S)
  5.     S1 = S[:-(n // 2)] + S[:n // 2][::-1]
  6.     if S1 > S:
  7.         return S1
  8.     n1 = (n + 1) // 2
  9.     n2 = n - n1
  10.     N = str(int(S[:n1]) + 1)  
  11.     S2 = N + N[:n2][::-1]
  12.     return S2
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement