समस्या
Decide whether the decimal digits of n read the same forwards and backwards. Negative numbers are never palindromes because of the minus sign.
Implement is_palindrome_number(n).
Input
n: The number to check.
Output
Return true for a palindromic number, otherwise false.
सीमाएँ
-10¹⁸ ≤ n ≤ 10¹⁸
उदाहरण
इनपुट:
n = 12321
अपेक्षित आउटपुट:
expected = True
इनपुट:
long long n = 12321;
अपेक्षित आउटपुट:
bool expected = true;
इनपुट:
long n = 12321;
अपेक्षित आउटपुट:
bool expected = true;
व्याख्या
12321 reversed is 12321.
इनपुट:
n = -121
अपेक्षित आउटपुट:
expected = False
इनपुट:
long long n = -121;
अपेक्षित आउटपुट:
bool expected = false;
इनपुट:
long n = -121;
अपेक्षित आउटपुट:
bool expected = false;
व्याख्या
The minus sign makes "-121" differ from "121-".
कैसे हल करें
पहले खुद कोशिश करें, फिर एक-एक करके संकेत खोलें।
संकेत 1
A negative number cannot be a palindrome because of the minus sign.
संकेत 2
Compare the number’s digits from both ends rather than converting unnecessarily.
संकेत 3
Single-digit numbers are always palindromes.
अपेक्षित जटिलता
O(log n) time, O(1) extra space
संदर्भ
यह चुनौती CodeUtility के लिए अनुकूलित की गई है। ऊपर दिए गए स्टेटमेंट और सीमाओं का पालन करें।