leetcode_c++:Longest Common Prefix(014)
来源:互联网 发布:南昌神起网络 编辑:程序博客网 时间:2024/05/16 09:56
Write a function to find the longest common prefix string amongst an array of strings.
求多个字串的最长前缀
算法
O(n^2)
class Solution { public: string longestCommonPrefix(vector<string> &strs) { // IMPORTANT: Please reset any member data you declared, as // the same Solution instance will be reused for each test case. if (strs.size() == 0) return ""; string prefix = strs[0]; for (int i = 1; i < strs.size(); ++i) { if (prefix.length() == 0 || strs[i].length() == 0) return ""; int len = prefix.length() < strs[i].length() ? prefix.length() : strs[i].length(); int j; for (j = 0; j < len; ++j) { if (prefix[j] != strs[i][j]) break; } prefix = prefix.substr(0,j); } return prefix; } };
0 0
- leetcode_c++:Longest Common Prefix(014)
- 014 - Longest Common Prefix
- LeetCode 014 Longest Common Prefix
- LeetCode 014 Longest Common Prefix
- LeetCode 014 Longest Common Prefix
- [LeetCode]014-Longest Common Prefix
- LeetCode 014 Longest Common Prefix
- leetcode-014-Longest Common Prefix
- LeetCode-014 Longest Common Prefix
- leetcode 014 —— Longest Common Prefix
- leetcode之路014 Longest Common Prefix
- leetcode解题方案--014--Longest Common Prefix
- LeetCode: Longest Common Prefix
- LeetCode Longest Common Prefix
- LeetCode : Longest Common Prefix
- [Leetcode] Longest Common Prefix
- leetcode6:Longest Common Prefix
- leetcode22: longest common prefix
- 深度学习算法实践5---线性回归算法实现
- 数学基础 —— 旋转(2D 正旋转)
- CSS-相對于父元素絕對定位
- android艺术开发探索之消息机制
- adb 和 shell、Logcat 常用命令
- leetcode_c++:Longest Common Prefix(014)
- SDUT3403数据结构实验之排序六:希尔排序
- 29. Divide Two Integers
- 使用proxifier代理LOL、橘子等游戏的教程
- 利用贝叶斯分类器进行文本挖掘---笔记
- HDU2188(巴什博奕)
- TCP、UDP区别
- ios scrollView联动处理-左边悬停、上面悬停
- 开始学习计算几何啦