20 lines
552 B
Python
20 lines
552 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]:
|
|
return return_string
|
|
return_string += strs[0][i]
|
|
i += 1
|
|
except:
|
|
return return_string
|
|
|
|
return return_string
|