add leetcode 14

This commit is contained in:
sangge-rockpi 2024-01-20 03:39:05 +08:00
parent 45bf6a557a
commit a95031128d

21
leetcode/14.py Normal file
View File

@ -0,0 +1,21 @@
# 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:
returnString = ""
index = 0
while i < len(str[0]):
try:
for string in strs:
if string[i] == strs[0][i]:
i += 1
returnString += string[i]
else:
break
except:
break
return returnString