-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path14.py
More file actions
24 lines (24 loc) · 697 Bytes
/
14.py
File metadata and controls
24 lines (24 loc) · 697 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
class Solution:
def longestCommonPrefix(self, strs):
min_length=200
if len(strs)==1:
return strs[0]
for i in strs:
min_length=min(min_length, len(i))
if min_length==0:
return ''
match=True
index=0
for index in range(min_length):
temp=strs[0][index]
for j in strs[1:]:
if temp!=j[index]:
match=False
break
if match is not True:
break
if match==True:
return strs[0][:index+1]
return strs[0][:index]
strs = ["abab","aba",""]
print(Solution().longestCommonPrefix(strs))