Palindrome String | Practice | GeeksforGeeks

Given a string S, check if it is palindrome or not.
Example 1:
Input: S = "abba"
Output: 1
Explanation: S is a palindrome
Example 2:
Input: S = "abc" 
Output: 0
Explanation: S is not a palindrome
 
Your Task: 
You don't need to read input or print anything. Complete the function isPlaindrome()which accepts string S and returns an integervalue 1 or 0.

Expected Time Complexity: O(Length of S)
Expected Auxiliary Space: O(1)

Constraints:
1 <= Length of S<= 105
0
1ashishchauhan2002in 6 hours
 string p=S;    reverse(p.begin(), p.end());    if(p==S) return 1;    else return 0;
0
penchalaswamimannarapu22814 hours ago
class Solution:def isPalindrome(self, S): # code here w='' for i in S:     w=i+w if w==S:     return 1      else:     return 0
0
parikshitgaikwad1721 day ago
int isPalindrome(string S)
	{
	    int i=0,j=S.size()-1;
	    while(i<=j){
	        if(S[i]==S[j]){
	            i++;
	            j--;
	            continue;
	        }else{
	            return 0;
	        }
	    }
	    return 1;
	    // Your code goes here
	}
0
mehtay0372 days ago
Python Solution:
class Solution:def isPalindrome(self, S): # code here if(S[::]==S[::-1]):     return '1' else:     return '0' 
0
suprithsk20013 days ago
//easy cpp soln
string str=S;    int s=0,e=str.length()-1;    while(s<e){        swap(str[s],str[e]);        s++;        e--;    }    if(str==S){                return 1;    }    else{        return 0;    }
0
visionsameer394 days ago
in pyhton 
s1=S[0]
return s1[0]==S[::-1]
0
priyansh708905 days ago
Simple Solution -
 int isPalindrome(string S){    // Your code goes here    int start = 0;    int end = S.length() - 1;    string str = S;    while(start < end)    {        swap(S[start++],S[end--]);    }    return S==str;}
0
singhvipnesh65 days ago
class Solution {   int isPalindrome(String S) {       int  l=0;       int r=S.length()-1;       while(l<r)       {           if(S.charAt(l)!=S.charAt(r)){           return 0;           }           l++;           r--;       }       return 1;   }};
0
codewithshoaib196 days ago
 int isPalindrome(String S) {       // code here       for(int i=0;i<S.length();i++){           if(S.charAt(i)!=S.charAt(S.length()-1-i)){               return 0;           }       }       return 1;   }
0
mayank180919996 days ago
	int isPalindrome(string S)
	{
	    // Your code goes here
	   string v;
        for(int i=S.length()-1;i>=0;i--){
             v.push_back(S[i]);
        }
        for(int i=0;i<S.length();i++){
            if(S[i]!=v[i]){
              return 0;
            }
         }
        return 1;
	}
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.