题目:Write a function to find the longest common prefix string amongst an array of strings.
链接:https://oj.leetcode.com/problems/longest-common-prefix/
描述:找出字符串数组中的最长公共前缀
solution by python:
class Solution:
# @return a string
def longestCommonPrefix(self, strs):
if not strs: return ''
ans = '';idx=0;flag=True
while flag:
c = None
for s in strs:
if idx>=len(s) or c != None and s[idx] != c:
flag = False
break
if c == None: c = s[idx]
if flag: ans += s[idx]
idx += 1
return ans