leetcode Longest Common Prefix python
2015-11-19 20:17
603 查看
class Solution(object): def longestCommonPrefix(self, strs): """ :type strs: List[str] :rtype: str """ if len(strs) <= 0: return "" shortestLen=None for tmp in strs: if len(tmp) < shortestLen or shortestLen == None: shortestLen = len(tmp) if shortestLen <= 0: return "" if len(strs) == 1: return strs[0] bolStop=False res="" firstStr=strs[0] del strs[0] for index in range(shortestLen): strCarry="" for tmpStr in strs: strNext = tmpStr[index] strCur = firstStr[index] if strNext != strCur: bolStop=True break elif strNext == strCur: strCarry=strCur if bolStop: break res+=strCarry return res
相关文章推荐
- Python爬虫笔记一
- 每天一点python——类
- Houdini otl bake fracture animation Python程序
- python的常见错误和异常
- python 安装mysqldb第三方库
- python之xlwt模块列宽width、行高Heights详解
- 第二天 Python列表的使用
- python 网页爬虫_正则匹配
- python中生成二维码图片
- python 备份脚本
- Python Decorators 3
- Thrift安装配置及使用python通过thrift连接HBase测试
- 利用Python脚本进行删除不需要的行数
- python中使用@property
- MAC下创建python虚拟环境
- python 字典排序,列表排序详细
- python 类方法 的调用
- python 模块的创建 和使用
- Python Argparse模块的使用例子,往python脚本传参数
- Python Decorator