Skip to content

Commit ec48434

Browse files
committed
Create 14.longest-common-prefix.py
1 parent 363e1c8 commit ec48434

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

14.longest-common-prefix.py

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# https://leetcode-cn.com/problems/longest-common-prefix/
2+
3+
from typing import List
4+
5+
6+
class Solution1:
7+
'''
8+
Date: 2022.04.14
9+
Pass/Error/Bug: 1/0/0
10+
执行用时: 36 ms, 在所有 Python3 提交中击败了 75.47% 的用户
11+
内存消耗:14.9 MB, 在所有 Python3 提交中击败了 96.39% 的用户
12+
'''
13+
def longestCommonPrefix(self, strs: List[str]) -> str:
14+
r = ''
15+
for i in list(map(set, zip(*strs))):
16+
if len(i) == 1:
17+
r += list(i)[0]
18+
else:
19+
break
20+
return r

0 commit comments

Comments
 (0)