from typing import List
class Solution:
def longestCommonPrefix(self, strs: List[str]) -> str:
result = ""
length = len(strs)
if (len == 0):
return result
if (length == 1):
return strs[0]
loop_len = len(strs[0])
for i in range(0, length):
if len(strs[i]) == 0:
return result
if len(strs[i]) < loop_len:
loop_len = len(strs[i])
for i in range(0, loop_len):
flag = 0
for j in range(1, length):
if strs[0][i] != strs[j][i]:
flag = 1
break
if flag == 1:
break
result += strs[0][i]
return result
if __name__ == '__main__':
solution = Solution()
input = ["flower", "flow", "flight"]
output = solution.longestCommonPrefix(input)
print(output)