...
Info |
---|
Input: ["flower", "flow", "flight" ] → Output: "fl" Input: ["dog", "racecar", "car"] → Output: "" |
Code Block | ||
---|---|---|
| ||
class Solution: def longestCommonPrefix(self, strs: List[str]) -> str: if not strs: return "" result="" cnt=len(strs) for i in range(len(strs[0])): j=1 while j<cnt and i<len(strs[j]) and strs[j][i]==strs[0][i]: j+=1 if j==cnt: result += strs[0][i] else: break; return result; |
...