P20833 [GeeksforGeeks] Closest palindrome4519
提高-
题目描述

Given a number num, our task is to find the closest Palindrome number whose absolute difference with given number is minimum. If 2 Palindome numbers have same absolute difference from the given number, then find the smaller one.

Example 1:
Input: num = 9
Output: 9
Explanation: 9 itself is a palindrome
number.
Example 2:
Input: num = 489
Output: 484
Expnataion: closest palindrome numbers from
489 are 484 and 494. Absolute difference between
489 and 494 is equal to the absolute difference
between 484 and 489 but 484 is smaller than 494.

Your Task:
You don't need to read or print anyhting. Your task is to complete the function closestPalindrome() which takes num as input parameter and returns the closest palindrome.

Expected Time Complexity: O(log_{10}num)
Expected Space Complexity: O(1)

Constraints:
1 <= num <= 10^{14}

输入格式

见题面

输出格式

见题面

样例输入
num = 9
样例输出
9