Next Palindrome Number
MediumStrings ยท Uber
Given a string n of decimal digits, return the smallest palindrome that is strictly greater than the number n represents, as a string.
A palindrome reads the same forwards and backwards, and the result has no leading zeros. n can be too long to fit in a machine integer.
Example 1
- Input:
- n = "123"
- Output:
- "131"
- Explanation
- The mirror of the left half is 121, which is too small, so the middle digit goes up to give 131.
Example 2
- Input:
- n = "99"
- Output:
- "101"
Example 3
- Input:
- n = "12321"
- Output:
- "12421"
- Explanation
nis already a palindrome, but the answer must be strictly larger.
Constraints
1 <= n.length <= 100000ncontains only digits and has no leading zerosnrepresents an integer of at least 1