Longest Common Prefix-LeetCode
来源:互联网 发布:js按钮置灰 不可点击 编辑:程序博客网 时间:2024/04/29 04:11
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.empty()||strs[0].empty()) { return ""; } vector <char> pre; pre.push_back(strs[0][0]); for (unsigned int i = 0; i < pre.size() ; i++) { for (unsigned int j = 0; j < strs.size(); j++) { if (strs[j].empty()) { return ""; } if (i >= strs[j].size() || pre[i] != strs[j][i]) { return strs[0].substr(0,i); } } if (i < strs[0].length() - 1) { pre.push_back(strs[0][i + 1]); } else { return strs[0]; } } }};
0 0
- LeetCode: Longest Common Prefix
- LeetCode Longest Common Prefix
- LeetCode : Longest Common Prefix
- [Leetcode] Longest Common Prefix
- [LeetCode] Longest Common Prefix
- [LeetCode]Longest Common Prefix
- LeetCode-Longest Common Prefix
- [LeetCode] Longest Common Prefix
- LeetCode - Longest Common Prefix
- leetcode Longest Common Prefix
- LeetCode | Longest Common Prefix
- Leetcode: Longest Common Prefix
- LeetCode: Longest Common Prefix
- 【LeetCode】Longest Common Prefix
- [LeetCode] Longest Common Prefix
- [LeetCode]Longest Common Prefix
- leetcode: Longest Common Prefix
- LeetCode Longest Common Prefix
- 悲剧了!iPad mini 3跑分出炉 性能下降30%
- 第九周项目4我的小九九
- 作业报告15 输出星号图2
- spring3.2.4配置文件
- 移动App乱象多 国信办要出台管理政策了
- Longest Common Prefix-LeetCode
- Application 判断当前是否还有Activity处于激活状态
- kindeditor粘贴word去除格式
- ARP协议的功能是什么?假设主机1和主机2处于同一局域网(主机1的IP地址是172.16.22.101,主机2的IP地址是172.16.22.110),简述主机1使用ARP协议解析主机2的物理地址的工
- 第九周项目6
- ubuntu中文乱码
- 开发Webview的技术,小的技术知识点
- 使用Tomcat构建web站点
- 逆天了!今年双11的快递预计将突破5亿件