String Palindrome
Given a string, determine if it is a palindrome, considering only alphanumeric characters.
C/C++,java,python c++ keywords, identifiers, data types,variables,modifiers,storage classes,operators,for loop ,while loop,do while loop,if else statement,nested loops,break continue goto statement,functions ,call by value call by reference ,arrays ,strings,pointers,data structures ,classes and objects,inheritance,polymorphism,operator overloading,function overloading,data abstraction,data encapsulation,dynamic memory allocation for array and objects,function templates,class templates,
String Palindrome
Given a string, determine if it is a palindrome, considering only alphanumeric characters.
A palindrome is a word, number, phrase, or other sequences of characters which read the same backwards and forwards.
If the input string happens to be, "malayalam" then as we see that this word can be read the same as forward and backwards, it is said to be a valid palindrome.
The expected output for this example will print, 'true'.
The first and only line of input contains a string without any leading and trailing spaces. All the characters in the string would be in lower case.
The only line of output prints either 'true' or 'false'.
You are not required to print anything. It has already been taken care of.
0 <= N <= 10^6
Where N is the length of the input string.
Time Limit: 1 second
abcdcba
true
coding
false
C++ Code:
bool checkPalindrome(char str[]){
if(str==nullptr) return true ;
int len=0;
while(str[len]!='\0')
len++;
int i=0, j=len-1;
while(i<j)
{
if(str[i]!=str[j])
{
return false;
}
i++;
j--;
}
return true;
}
0 comments:
Post a Comment