Code Challenge : Palindrome Checker

Publié le: 05 janvier 2024
sur la chaîne: All About Python
159
4

Let’s try a simple coding challenge of checking palindromes in python.

A palindrome is a type of string that returns the same value if read from both sides.

Palindrome string can also have spaces in them but they are ignored, for example:

“never a foot too far even” is a palindrome.

So how do we write it.

The simplest way is to just reverse the string and compare, but here is another way to do it.

Create two pointer variables, start and end. Set start to 0 and end to length of string minus 1

Create a while loop that runs until start is less than end.

Within the loop if character at start position is space, we ignore it and increment start.

If character at end position is space, we ignore it and increment end.

If character at start and end are not same, we return false as the string cannot be palindrome now.

If none of these conditions match, just increment start and end.

If the code runs through the while loop successfully, return true

If you liked this code challenge, make sure to follow.


Sur cette page du site, vous pouvez voir la vidéo en ligne Code Challenge : Palindrome Checker durée heure minute seconde en bonne qualité , qui a été Téléchargé par l'utilisateur All About Python 05 janvier 2024, Partagez le lien avec vos amis et connaissances, sur youtube cette vidéo a déjà été regardée 159 fois et il a aimé 4 téléspectateurs. Bon visionnage!