Shared Starting Text

Autocomplete in IDEs and search often starts from the part that all suggestions have in common. The function longest_common_prefix receives a list of strings strs. Find the longest prefix that every string in the list starts with. If there is no shared beginning, return an empty string.

Примеры

Ввод
[["flower", "flow", "flight"]]
Вывод
"fl"
Ввод
[["dog", "racecar", "car"]]
Вывод
""
Ввод
[["interspecies", "interstellar", "interstate"]]
Вывод
"inters"

Нужно реализовать

def longest_common_prefix(strs):

Теги

strings
PostgreSQLv16

Le résultat de l'exécution du code s'affichera ici

Visible tests
1
Input
["flower","flow","flight"]
Expected"fl"
2
Input
["dog","racecar","car"]
Expected""
3
Input
["interspecies","interstellar","interstate"]
Expected"inters"
4
Input
["same","same","same"]
Expected"same"
5
Input
[]
Expected""
6
Input
["a"]
Expected"a"
Focus radio
Paused · SomaFM · Fluid