MCPcopy Create free account
hub / github.com/HuberTRoy/leetCode / longestCommonPrefix

Method longestCommonPrefix

String/LongestCommonPrefix.py:34–49  ·  view source on GitHub ↗

:type strs: List[str] :rtype: str

(self, strs)

Source from the content-addressed store, hash-verified

32"""
33class Solution(object):
34 def longestCommonPrefix(self, strs):
35 """
36 :type strs: List[str]
37 :rtype: str
38 """
39 result = ""
40
41 for i in zip(*strs):
42 a = i[0]
43 for j in i[1:]:
44 if j != a:
45 return result
46 else:
47 result += a
48
49 return result
50

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected