Palindrome | Practice | GeeksforGeeks

Given an integer, check whether it is a palindrome or not.

Example 1:
Input: n = 55555
Output: Yes


Example 2:
Input: n = 123
Output: No

 
Your Task:
You don't need to read or print anything. Your task is to complete the function is_palindrome() which takes the number as input parameter and returns "Yes" if it is palindrome otherwise returns "No"(Without quotes).
 
Expected Time Complexity: O(x)
Expected Space Complexity: O(x) where x is number of digits in n.
 
Constraints:
1 <= n <= 1000
0
adeshs11111 week ago
Ok
0
ekansh25sanskar2 weeks ago
class Solution{public: string is_palindrome(int n) {        // Code here.     int x=0,temp=n;     while(n!=0){         x=(x*10)+(n%10);         n/=10;     }     if(x==temp) cout<<"Yes";     else cout<<"No";}};
0
shivanshm20013 weeks ago
RECURSIVE SOLUTION
class Solution{public:    string check(string &str,int N,int M)    {        if(N==0 && M==str.size())        {            return "Yes";        }        if(str[N-1]==str[M])        {            check(str,N-1,M+1);            return "Yes";        }        else         return "No";             } string is_palindrome(int n) {     // Code here.    string str=to_string(n);     string ans=check(str,str.size(),0);    return ans; }
0
shwetarpatil233 weeks ago
 string is_palindrome(int n) {         int temp = n;     int reverse = 0;          while(temp !=0){                  int r = temp %10;          reverse = (reverse * 10) + r;         temp = temp / 10;     }          return (n == reverse)?"Yes":"No";      }
0
avicode4241 month ago
class Solution {   // function to return sum of  1, 2, ... n   long seriesSum(int n){       // code here              if(n<=0)       {           return 0;       }       long sum = n+seriesSum(n-1);       return sum;          }}
0
meetsangani6338meet2 months ago
class Solution
{
	public:
		string is_palindrome(int n)
		{
		    // Code here.
		   
		    string s1=to_string(n);
		    string s2=s1;
		    
		    reverse(s2.begin(),s2.end());
		    if(s1==s2)
		    {
		        return "Yes";
		    }
		    
		    else
		        return "No";
		}
};
0
sdmrf2 months ago
 Python Soln:
def is_palindrome(self, n):    if str(n)==str(n)[::-1]: return "Yes"    else: return "No"
0
imranmbhd24122 months ago
###CPP
string is_palindrome(int b) {     int c = b, x{};     while (b) {         x = x*10 + b%10;         b/=10;     }     return c == x? "Yes":"No"; }
0
0niharika22 months ago
int rev=0, original = n;     while(n){         rev = rev*10 + n%10;         n/=10;     }     if(rev==original)         return "Yes";     else         return "No";
0
madhurimasantra19992 months ago
class Solution{   public String is_palindrome(int n)   {       int rev=0,rem,original,i;       original=n;       while(n!=0)       {           rem=n%10;           n=n/10;           rev=(rev*10)+rem;       }       if(original==rev)           return "Yes";       else           return "No";   }}
We strongly recommend solving this problem on your own before viewing its editorial. Do you still
                    want to view the editorial?
 Login to access your submissions. 

Problem


Contest

Reset the IDE using the second button on the top right corner.
Avoid using static/global variables in your code as your code is tested against multiple test cases and these tend to retain their previous values.
Passing the Sample/Custom Test cases does not guarantee the correctness of code. On submission, your code is tested against multiple test cases consisting of all possible corner cases and stress constraints.
You can access the hints to get an idea about what is expected of you as well as the final solution code.
You can view the solutions submitted by other users from the submission tab.