Skip to content

Commit 49f4361

Browse files
fix 14 python
1 parent 5946ab0 commit 49f4361

File tree

1 file changed

+5
-11
lines changed
  • src/0014-Longest-Common-Prefix

1 file changed

+5
-11
lines changed

src/0014-Longest-Common-Prefix/0014.py

+5-11
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,8 @@ def longestCommonPrefix(self, strs):
66
"""
77
if not strs:
88
return ''
9-
res = ''
10-
min_val = min(strs)
11-
min_val, strs[0] = strs[0], min_val
12-
print(min_val)
13-
for i, c in enumerate(strs[0]):
14-
if not all([s[i] == c for s in strs[1:]]):
15-
break
16-
res += c
17-
18-
return res
19-
9+
for i, word in enumerate(zip(*strs)):
10+
if len(set(word)) > 1:
11+
return strs[0][:i]
12+
else:
13+
return min(strs)

0 commit comments

Comments
 (0)