categories: computer science
Hello everyone,
Below you will find a video with a detailed explanation of the algorithm for determining whether a given word is a palindrome. Its operation, time complexity, and usefulness. Below you will also find ready-made code to copy if needed.
slowo1 = "abcdefg"
slowo2 = "abcdefghijk"
def ktoreWieksze(slowo1, slowo2):
for i in range(min(len(slowo1), len(slowo2))):
if slowo1[i].lower() < slowo2[i].lower():
return slowo2
elif slowo1[i].lower() > slowo2[i].lower():
return slowo1
if len(slowo1) < len(slowo2):
return slowo2
else:
return slowo1
print(ktoreWieksze(slowo1, slowo2))
Code:
def palindrom(slowo):
polowa = len(slowo) // 2
czy = True
for i in range(polowa):
if slowo[i] != slowo[len(slowo) - 1 - i]:
czy = False
return czy
print(palindrom("slowo"))
Video:
Thank you for reading!
Read more