First Mirror Word
A palindrome reads the same from left to right and from right to left, like a small mirror word. Write a function first_palindrome that scans the list words in order. Return the first string that is a palindrome. If no palindrome exists, return an empty string.
Примеры
Ввод
["abc", "car", "ada", "racecar", "cool"]Вывод
"ada"Ввод
["notapalindrome", "racecar"]Вывод
"racecar"Ввод
["def", "ghi"]Вывод
""Нужно реализовать
def first_palindrome(words: list[str]) -> str:
Теги
stringsarraytwo-pointers
Jelentkezz be a beküldési előzmények megtekintéséhez
BejelentkezésJelentkezz be az MI-mentor használatához
BejelentkezésVisible tests
1
Input
["abc","car","ada","racecar","cool"]Expected
"ada"2
Input
["notapalindrome","racecar"]Expected
"racecar"3
Input
["def","ghi"]Expected
""4
Input
["a"]Expected
"a"5
Input
["ab","ba","aa"]Expected
"aa"6
Input
[]Expected
""Focus radio
Paused · SomaFM · Fluid