-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproblem14.py
More file actions
31 lines (29 loc) · 745 Bytes
/
problem14.py
File metadata and controls
31 lines (29 loc) · 745 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
25
26
27
28
29
30
31
'''
Pretty ez, gonna skip.
'''
class Solution(object):
def longestCommonPrefix(self, strs):
"""
:type strs: List[str]
:rtype: str
"""
if strs == []:
return ""
prefix = strs[0]
for i in strs[1:]:
index = 0
lens = min(len(prefix),len(i))
while index < lens:
if prefix[index] == i[index]:
index += 1
else:
break
if index == 0:
return ""
else:
prefix = prefix[:index]
return prefix
if __name__ == '__main__':
strs = ["flower","flow","flight"]
s = Solution()
print s.longestCommonPrefix(strs)