0
How to code for Palindrome?
4 Réponses
+ 9
A palindrome is a string that reads the same backwards and forwards. In Python, you can use slice notation to reverse a string. Here is an example:
"Hello"[::-1] == "olleH'
+ 6
https://code.sololearn.com/Wi5nCdKdSY3E/?ref=app
https://code.sololearn.com/csjz9Khf9GHr/?ref=app
check this code u might help
+ 2
You could compare the first letter in your String with the last one and iterate to the middle as long as they are equal. You may should pay attention to words with an odd length. But the concept is a simple on. Here is an example:
word: anna
1st iteration: a==a --> true
2nd iteration: n==n --> true
3rd iteration: no more letters left --> it's a palindrome
next word: abcba
1st: a==a --> true
2nd: b==b --> true
3rd: one character left --> it's a palindrome
next word: xyzzx
1st; x==x --> true
2nd: y==z --> false --> no palindrome
Hope these are enough hints. If you have some issues following the hints, feel free to ask.
+ 1
thanks peers!