add leetcode 14
This commit is contained in:
parent
45bf6a557a
commit
a95031128d
21
leetcode/14.py
Normal file
21
leetcode/14.py
Normal 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
|
||||
|
Loading…
x
Reference in New Issue
Block a user