14. Longest Common Prefix
2016-07-26 19:34
453 查看
14. Longest Common Prefix
Leetcode link for this questionDiscription:
Write a function to find the longest common prefix string amongst an array of strings.Analyze:
Code 1:
class Solution(object): def longestCommonPrefix(self, strs): """ :type strs: List[str] :rtype: str """ if not strs: return "" if not strs[0]: return "" l=0 tmp=strs[0][l] while 1: for i in strs: if l>=len(i): return strs[0][0:l] if i[l] !=tmp: return strs[0][0:l] l+=1 if l>=len(strs[0]): return strs[0][0:l] tmp=strs[0][l] return strs[0][0:l+1]
Submission Result:
Status: AcceptedRuntime: 52 ms
Ranking: beats 73.43%
相关文章推荐
- 命令的查看帮助 和 命令行的历史
- Material Design的其他使用
- 13. Roman to Integer
- UVALive - 2701 Find The Multiple
- 阅一道简单程序,了解多线程编程;
- drop table中cascade的含义及用法
- 7. Reverse Integer
- Dynamics CRM 2016 修改服务器名字
- [SCU4437] Carries [2015 Sichuan Province Contest Final B]
- 6. ZigZag Conversion
- Linux-(C)多线程学习(入门)
- 弹性ListView
- 使用Android Studio查找文件中含有中文字符串位置(正则表达式)
- 1. Two Sum
- Android SyncAdapter同步实践
- 小明的求助
- OI总结(垃圾排版就忽略了吧)
- HDU 5761 Rower Bo
- 如何灵活运用转义字符还有玩转常量0726
- 通过KEPWARE ODBC DRIVER和ADVANCED TAG 实现数据库和PLC的双向通信