Search
 
SCRIPT & CODE EXAMPLE
 

CPP

Palindrome String

Input: S = "abba"Output: 1Explanation: S is a palindrome
int isPalindrome(string S)
	{
	    string st = S;
	    char temp;
	    int i=0, j= st.length()-1;
	    while(j>i)
	    {
	       if(S[i] != S[j])
	       {
	           return 0;
	       }
	       i++;
	       j--;
	    }
	    return 1;
	}
Comment

palindrome string

const isPalindrome = (str) => {
    
    const preprocessing_regex = /[^a-zA-Z0-9]/g,
    processed_string = str.toLowerCase().replace(preprocessing_regex , ""),
    integrity_check = processed_string.split("").reverse().join("");
    if(processed_string === integrity_check) return true
    else return false
         
        }

//if you find this answer is useful ,
//upvote ⇑⇑ , so can the others benefit also . @mohammad alshraideh ( ͡~ ͜ʖ ͡°)
Comment

minimum characters to make string palindrome

string s;
    int len=0,i=1;
    cin>>s;
    int n=s.size();
    vector<int> LPS(n);
    LPS[0]=0;
    while(i<n)
    {
        if(s[i]==s[len]) LPS[i++]=++len;
        else
        {
            if(len==0) LPS[i++]=0;
            else len=LPS[len-1];
        }
    }
Comment

check if string is a palindrome

<script>
  // function that check str is palindrome or not
  function check_palindrome( str )
  {
    let j = str.length -1;
    for( let i = 0 ; i < j/2 ;i++)
    {
      let x = str[i] ;//forward character
      let y = str[j-i];//backward character
      if( x != y)
      {
        // return false if string not match
        return false;
      }
    }
    /// return true if string is palindrome
    return true;
     
  }
 
  //function that print output is string is palindrome
  function is_palindrome( str )
  {
    // variable that is true if string is palindrome
    let ans = check_palindrome(str);
    //condition checking ans is true or not
    if( ans == true )
    {
      console.log("passed string is palindrome ");
    }
    else
    {
      console.log("passed string not a palindrome");
    }
  }
  // test variable
  let test = "racecar";
  is_palindrome(test);
</script>
Comment

Checking String Palindrome

int main()
{
    char str1[20], str2[20];
    int i, j, len = 0, flag = 0;
    cout << "Enter the string : ";
    gets(str1);
    len = strlen(str1) - 1;
    for (i = len, j = 0; i >= 0 ; i--, j++)
        str2[j] = str1[i];
    if (strcmp(str1, str2))
        flag = 1;
    if (flag == 1)
        cout << str1 << " is not a palindrome";
    else
        cout << str1 << " is a palindrome";
    return 0;
}
Comment

Checking String Palindrome

int main()
{
    char str1[20], str2[20];
    int i, j, len = 0, flag = 0;
    cout << "Enter the string : ";
    gets(str1);
    len = strlen(str1) - 1;
    for (i = len, j = 0; i >= 0 ; i--, j++)
        str2[j] = str1[i];
    if (strcmp(str1, str2))
        flag = 1;
    if (flag == 1)
        cout << str1 << " is not a palindrome";
    else
        cout << str1 << " is a palindrome";
    return 0;
}
Comment

palindrome string

int isPlaindrome(string S)
	{
	    // Your code goes here
	    int flag =0;
	    int l=0;
	    int h=S.length()-1;
	    while(h>l){
	        if(S[l++]!=S[h--]){
	         return 0;
	        }
	    }
	    return 1;
	}
Comment

Palindrome String

Input: S = "abc" Output: 0Explanation: S is not a palindrome
Comment

PREVIOUS NEXT
Code Example
Cpp :: for statement in c++ 
Cpp :: template function in class c++ 
Cpp :: add for input output file in c/c++ 
Cpp :: vector to char array c++ 
Cpp :: string to wstring conversion c++ 
Cpp :: in c++ 
Cpp :: Arduino Counting without Millis 
Cpp :: c++ loop array 
Cpp :: hello world program in c ++ using standard namespace 
Cpp :: what does for do in c++ 
Cpp :: is the c++ 20 char te same as the old one 
C :: remix icon cdn 
C :: what is meaning of product *= in c 
C :: .gitkeep file 
C :: how to use gets after scanf 
C :: c program to find area of circle 
C :: tainted love 
C :: Write a C program to find reverse of an array 
C :: arduino digital read 
C :: get time to complete code c 
C :: how to print a file c 
C :: divide and conquer program in c 
C :: mariadb utf8mb4 
C :: for loop in c 
C :: slug urls django 
C :: comment in c language 
C :: addition of two numbers in c 
C :: simple calculator, using switch statement in C 
C :: doble puntero en c 
C :: addition of matrix 
ADD CONTENT
Topic
Content
Source link
Name
5+8 =