From a68ee4772790617a43bb23ab34dde351d5186ce3 Mon Sep 17 00:00:00 2001 From: vlakshmipriya711-bot Date: Tue, 17 Feb 2026 18:24:56 +0530 Subject: [PATCH] Updated the Palindrome Logic for integer checks Refactor palindrome check to use a function and remove built-in string reversal. --- Check Palindrome Without Built-in Functions | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/Check Palindrome Without Built-in Functions b/Check Palindrome Without Built-in Functions index 5c4543b..b7241d8 100644 --- a/Check Palindrome Without Built-in Functions +++ b/Check Palindrome Without Built-in Functions @@ -1,7 +1,11 @@ -s = input().strip() -rev = "" +# checking the palindrome of a number -for ch in s: - rev = ch + rev +def palindrome(num): + if num==0 or (num%10==0 and num!=0): # checks if the number is not zero and it is not multiple of 10. + return False -print("Palindrome" if s == rev else "Not Palindrome") + rev=0 + while num > rev: + rev = rev*10+num%10 # adds the number in reverse order + num=num//10 # decreases the number + return num==rev or num==rev//10