Skip to content

Commit 07a61d9

Browse files
committed
Update solution 014 [Python3]
1 parent f80d373 commit 07a61d9

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
class Solution:
2+
def longestCommonPrefix(self, strs):
3+
"""
4+
:type strs: List[str]
5+
:rtype: str
6+
"""
7+
if strs == []:
8+
return ''
9+
if len(strs) == 1:
10+
return strs[0]
11+
strs.sort(key=lambda x : len(x))
12+
flag=False
13+
prefix=''
14+
for j in range(1,len(strs[0])+1):
15+
prefix=strs[0][:j]
16+
for i in range(1,len(strs)):
17+
if prefix == strs[i][:j]:
18+
flag=True
19+
else:
20+
flag=False
21+
if not flag:
22+
prefix0=prefix[:-1]
23+
return prefix0
24+
break
25+
return prefix

0 commit comments

Comments
 (0)