2024-01-20 12:53:20 +08:00

20 lines
522 B
Python

# find the longest common prefix
# 1 <= strs.length <= 200
# 0 <=strs[i].length <= 200
# only lowercase
class Solution:
def longestCommonPrefix(self, strs: list[str]) -> str:
return_string = ""
i = 0
while i < len(strs[0]):
try:
for string in strs:
if string[i] != strs[0][i]:
break
return_string += strs[0][i]
i += 1
except:
break
return return_string