1、当strs为空,直接输出“”

2、当strs中含有“”,直接输出“”

3、strs[0]的最长长度由最短公共长度l决定(code line:15)

 class Solution:
# @return a string
def longestCommonPrefix(self, strs):
if strs == []:
return ""
for i in range(1,len(strs)):
l1 = len(strs[0])
l2 = len(strs[i])
if l1>l2:
l = l2
else:
l = l1
if l==0:
return ""
strs[0]=strs[0][0:l]
for j in range(l):
if strs[0][j] != strs[i][j]:
strs[0] = strs[0][0:j]
break
return strs[0]

leetcode:Longest Common Prefix【Python版】的更多相关文章

  1. leetcode Longest Common Prefix python

    class Solution(object): def longestCommonPrefix(self, strs): """ :type strs: List[str ...

  2. [LeetCode] Longest Common Prefix 最长共同前缀

    Write a function to find the longest common prefix string amongst an array of strings. 这道题让我们求一系列字符串 ...

  3. Leetcode Longest Common Prefix

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

  4. Leetcode::Longest Common Prefix && Search for a Range

    一次总结两道题,两道题目都比较基础 Description:Write a function to find the longest common prefix string amongst an a ...

  5. LeetCode: Longest Common Prefix 解题报告

    Longest Common Prefix Write a function to find the longest common prefix string amongst an array of ...

  6. [LeetCode] Longest Common Prefix 字符串公有前序

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

  7. LeetCode——Longest Common Prefix

    Write a function to find the longest common prefix string amongst an array of strings. 写一个函数找出字符串数组中 ...

  8. [转][LeetCode]Longest Common Prefix ——求字符串的最长公共前缀

    题记: 这道题不难但是很有意思,有两种解题思路,可以说一种是横向扫描,一种是纵向扫描. 横向扫描:遍历所有字符串,每次跟当前得出的最长公共前缀串进行对比,不断修正,最后得出最长公共前缀串. 纵向扫描: ...

  9. LeetCode Longest Common Prefix 最长公共前缀

    题意:给多个字符串,返回这些字符串的最长公共前缀. 思路:直接逐个统计同一个位置上的字符有多少种,如果只有1种,那么就是该位是相同的,进入下一位比较.否则终止比较,返回前缀.可能有一个字符串会比较短, ...

随机推荐

  1. codeforces 536a//Tavas and Karafs// Codeforces Round #299(Div. 1)

    题意:一个等差数列,首项为a,公差为b,无限长.操作cz是区间里选择最多m个不同的非0元素减1,最多操作t次,现给出区间左端ll,在t次操作能使区间全为0的情况下,问右端最大为多少. 这么一个简单题吞 ...

  2. Jersey 2.x 探索新建的工程

    如果用 Jersey maven archetype 成功创建了这个项目,那么在你当前的路径下就已经创建了一个名为simple-service项目.它包含了一个标准的Maven项目结构: 说明 文件目 ...

  3. 悟空CRM框架下载模板

    1.你可以把你要下载的模板放在这个项目的Public/excelmodel目录下,然后你就可以在页面中编写代码 你可以在下载按钮这里编写:onclick="window.location.h ...

  4. 最全面的mac下的android studio快捷键

    Action Mac OSX Win/Linux 注释代码(//) Cmd + / Ctrl + / 注释代码(/**/) Cmd + Option + / Ctrl + Alt + / 格式化代码 ...

  5. WebService学习总结(转)

    原文地址: WebService学习总结(一)——WebService的相关概念 WebService学习总结(二)——WebService相关概念介绍 WebService学习总结(三)——使用JD ...

  6. 应用多种变形CSS3

    <!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml"><head>    < ...

  7. MVC,重写AuthorizeAttribute实现自己的权限验证(一)

    我们要实现下面的效果,某个controller,只允许某几个角色访问(admin,user,document controller) [MyAuthorize(Roles = "Admin, ...

  8. currentSession

    public  class  HibernateUtil  {  public static final ThreadLocal session =new ThreadLocal();  public ...

  9. zoj3732&& hdu4797 Graph Reconstruction

    Graph Reconstruction Time Limit: 2 Seconds      Memory Limit: 65536 KB      Special Judge Let there ...

  10. String对象中的正则表达式

    (1)身份证号码验证身份证号码是18位数字,根据GB11643-1999<公民身份证>定义制作:由17位本体码和一位校验码组成.身份证号码前6位是地址码,按(GB/T2260)规定执行.接 ...