【leetcode】Longest Common Prefix

题目简述:

Write a function to find the longest common prefix string amongst an array of strings.

解题思路:

class Solution:
# @return a string
def longestCommonPrefix(self, strs):
if strs == []:
return ''

minl = 99999
for i in strs:
if len(i) < minl:
minl = len(i)

pre = ''
for i in range(minl):
t = strs[0][i]
for j in range(1,len(strs)):
if t != strs[j][i]:
return pre
pre += t
return pre

posted @ 2015-03-29 18:51  mrbean  阅读(221)  评论(0)    收藏  举报