【LeetCode with Python】 Longest Common Prefix
2014-07-06 15:07
405 查看
博客域名:http://www.xnerv.wang
原题页面:https://oj.leetcode.com/problems/longest-common-prefix/
题目类型:
难度评价:★
本文地址:/article/1377506.html
Write a function to find the longest common prefix string amongst an array of strings.
原题页面:https://oj.leetcode.com/problems/longest-common-prefix/
题目类型:
难度评价:★
本文地址:/article/1377506.html
Write a function to find the longest common prefix string amongst an array of strings.
class Solution: def findPrefix(self, str1, str2): min_len = min(len(str1), len(str2)) for i in range(0, min_len): if str1[i] != str2[i]: return str1[0:i] return str1[0:min_len] # @return a string def longestCommonPrefix(self, strs): if None == strs: return "" n = len(strs) if 0 == n: return "" elif 1 == n: return strs[0] prefix = strs[0] for str in strs[1:]: prefix = self.findPrefix(prefix, str) if "" == prefix: break return prefix
相关文章推荐
- 【Leetcode】【python】Longest Common Prefix
- Leetcode-Longest Common Prefix-Python
- [LeetCode]题解(python):014-Longest Common Prefix
- [leetcode] Longest Common Prefix @ Python
- [leetcode]Longest Common Prefix @ Python
- [leetCode By Python] 14. Longest Common Prefix
- LeetCode 14 Longest Common Prefix (C,C++,Java,Python)
- Longest Common Prefix Leetcode Python Java
- 【LeetCode 14】Longest Common Prefix(Python)
- [leetcode:python]14.Longest Common Prefix
- python写算法题:leetcode: 14. Longest Common Prefix
- leetcode Longest Common Prefix python
- leetcode:Longest Common Prefix【Python版】
- LeetCode 14 — Longest Common Prefix(C++ Java Python)
- [LeetCode] 014. Longest Common Prefix (Easy) (C++/Java/Python)
- Longest Common Prefix(寻找最长前缀) 【leetcode】
- LeetCode-Longest Common Prefix
- [leetcode刷题系列]Longest Common Prefix
- LeetCode: Longest Common Prefix
- LeetCode-Longest Common Prefix