Question:
How to check whether string is palindrome or not using C++

Summary

Let's assume:

String- S

Function

isPalindrome()


Solution

//User function template for C++

class Solution{

public:

int isPalindrome(string S)

{

    // Your code goes here

    int n=0,m=0,x=0;

    while(S[n]!='\0') {

        n++;

    }

    if(n%2==0) {

        m=n/2;

    } else {

        m= (n/2) + 1;

    }

    for(int i=0; i<m; i++) {

        if(S[i]!=S[n-i-1]) {

            return 0;

        }

    }

    return 1;

}


};


Answered  by:> >nikhil07rlwhm

Credit: GeekforGeeks 


Suggested blogs:

>How to route between different components in React.js?

>How to save python yaml and load a nested class?-Python

>How to send multiple HTML form fields to PHP arrays via Ajax?

>What is data binding in Angular?

>What is microservice architecture, and why is it better than monolithic architecture?



Nisha Patel

Nisha Patel

Submit
0 Answers