0014._Longest_Common_Prefix
014. Longest Common Prefix
难度: Easy
刷题内容
原题连接
内容描述
Write a function to find the longest common prefix string amongst an array of strings.
If there is no common prefix, return an empty string ""
.
Example 1:
1 | Input: ["flower","flow","flight"] |
Example 2:
1 | Input: ["dog","racecar","car"] |
Note:
All given inputs are in lowercase letters a-z
.
解题方案
思路
**- 时间复杂度: O(N)**- 空间复杂度: O(N)**
代码:
1 | /** |