Jan 132021
题目很简单,寻找开头相同的字母,看看最大是多少。
https://leetcode.com/problems/longest-common-prefix/
每次看到这种题目,都有一种想法,如果python,有一个内置函数搞定这种看上去比较普遍的问题,多好。没想到这个问题,就是这种情况。居然有内置的函数,直接搞定。
Input: strs = [“flower”,”flow”,”flight”]
Output: “fl”
上面的朋友用了10种方法来解答,我最喜欢的,还是最后一种。
class Solution: def longestCommonPrefix(self, strs: List[str]) -> str: return os.path.commonprefix(strs)