आसान 0 हल किए गए 0% स्वीकृति

Palindrome Number

Check whether a number reads the same backwards.

आप क्या सीखेंगे

  • Reverse a number digit by digit
  • Compare the reversed value with the original
  • Handle negative numbers and trailing zeros

समस्या

अनुवाद दिखाएँ

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¹⁸

उदाहरण

उदाहरण 1
इनपुट:
n = 12321

अपेक्षित आउटपुट:
expected = True
इनपुट:
long long n = 12321;

अपेक्षित आउटपुट:
bool expected = true;
इनपुट:
long n = 12321;

अपेक्षित आउटपुट:
bool expected = true;

व्याख्या

12321 reversed is 12321.

उदाहरण 2
इनपुट:
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 के लिए अनुकूलित की गई है। ऊपर दिए गए स्टेटमेंट और सीमाओं का पालन करें।

दूसरों से सीखें

समुदाय समाधान

अभी तक कोई प्रकाशित समाधान नहीं। पहला साझा करने के लिए इस चुनौती को हल करें।