2017.10.27 LeetCode - 14. Longest Common Prefix
2017-10-27 16:40
288 查看
14. Longest Common Prefix
Description
Write a function to find the longest common prefix string amongst an array of strings.题意: 让你求出字符串数组中最长公共前缀并输出
分析: 直接拿第一个字符串来和后面的进行比较如果对应的每位都相等的话那么就在最后的答案里加上这个字符,详细见函数
参考函数
class Solution { public: string longestCommonPrefix(vector<string>& strs) { if(!strs.size()) return ""; string res = "",t = ""; for(int i = 0;i < strs[0].size();res+=strs[0][i],i++) { for(int j = 1;j < strs.size();j++) { if(strs[0][i] != strs[j][i]){ return res; } } } return res; } };
相关文章推荐
- leetcode 14. Longest Common Prefix
- LeetCode *** 14. Longest Common Prefix
- [LeetCode]14_Longest Common Prefix
- LeetCode 14. Longest Common Prefix
- leetcode 14. Longest Common Prefix
- Leetcode 14 Longest Common Prefix
- [leetcode 14] Longest Common Prefix
- LeetCode(14)Longest Common Prefix
- leetcode 14 Longest Common Prefix
- leetcode -- 14. Longest Common Prefix
- leetcode -- 14. Longest Common Prefix
- LeetCode之14---Longest Common Prefix
- LeetCode 14 Longest Common Prefix (C,C++,Java,Python)
- LeetCode 14.Longest Common Prefix
- 【LeetCode从零单排】No14.LongestCommonPrefix
- Leetcode||14.Longest Common Prefix
- [LeetCode] 14 - Longest Common Prefix
- leetcode-14-Longest Common Prefix
- 【leetcode】14. Longest Common Prefix
- [Leetcode 18] 14 Longest Common Prefix