Given a string, write a python function to check if it is palindrome or not. A string is said to be palindrome if the reverse of the string is the same as string. For example, “radar” is a palindrome, but “radix” is not a palindrome.
Input : malayalam Output : Yes Input : geeks Output : No
1) Find reverse of string
2) Check if reverse and original are same or not.
Iterative Method: This method is contributed by Shariq Raza. Run a loop from starting to length/2 and check the first character to the last character of the string and second to second last one and so on …. If any character mismatches, the string wouldn’t be a palindrome.
Below is the implementation of above approach:
Method using inbuilt function to reverse a string: This method is contributed by Shariq Raza. In this method, predefined function ‘ ‘.join(reversed(string)) is used to reverse string.
Below is the implementation of the above approach:
Method using one extra variable: In this method user take a character of string one by one and store in a empty variable.After storing all the character user will compare both the string and check whether it is palindrome or not.
This article is contributed by Sahil Rajput. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.
- Python program to check whether the string is Symmetrical or Palindrome
- Python program to check if given string is vowel Palindrome
- C Program to Check if a Given String is Palindrome
- Java program to check whether a string is a Palindrome
- Python program to check if number is palindrome (one-liner)
- Check if a given string is Even-Odd Palindrome or not
- Python program to check if string is empty or not
- Python program to check if a given string is Keyword or not
- Python program to check if given string is pangram
- Check if any anagram of a string is palindrome or not
- Check if a given string is a rotation of a palindrome
- Check if a string is palindrome in C using pointers
- Check if it is possible to create a palindrome string from given N
- Check given string is oddly palindrome or not
- Check given string is oddly palindrome or not | Set 2
- Check whether the given string is Palindrome using Stack
- Program to check if an Array is Palindrome or not
- Python program to check if a string contains all unique characters
- Given two strings check which string makes a palindrome first
- Recursive function to check if a string is palindrome