Skip to content

Commit 62f34be

Browse files
authored
Merge pull request #3192 from doublewhy/patch-1
Update 0014-longest-common-prefix.py
2 parents 84ebad3 + 7ee6b79 commit 62f34be

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

python/0014-longest-common-prefix.py

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
class Solution:
22
def longestCommonPrefix(self, strs: List[str]) -> str:
3-
res = ""
43
for i in range(len(strs[0])):
54
for s in strs:
6-
if i == len(s) or s[i] != strs[0][i]:
7-
return res
8-
res += strs[0][i]
9-
return res
5+
if i >= len(s) or s[i] != strs[0][i]:
6+
return strs[0][:i]
7+
return strs[0]

0 commit comments

Comments
 (0)