68. Longest Common Prefix
Longest Common Prefix
Write a function to find the longest common prefix string amongst an array of strings.
思路:两两字符串挨着找。水题。
string commonPrefix(string s1, string s2){
if(s1 == "" || s2 == "") return "";
int k = 0, len1 = s1.length();
while(k < len1 && s1[k] == s2[k]) ++k;
return s1.substr(0, k);
} class Solution {
public:
string longestCommonPrefix(vector<string> &strs) {
int len = strs.size();
if(len == 0) return "";
string s(strs[0]);
for(int i = 1; i < len; ++i){
if(s == "") return s;
s = commonPrefix(s, strs[i]);
}
return s;
}
};
68. Longest Common Prefix的更多相关文章
- [LeetCode] Longest Common Prefix 最长共同前缀
Write a function to find the longest common prefix string amongst an array of strings. 这道题让我们求一系列字符串 ...
- 【leetcode】Longest Common Prefix
题目简述: Write a function to find the longest common prefix string amongst an array of strings. 解题思路: c ...
- LintCode 78:Longest Common Prefix
public class Solution { /** * @param strs: A list of strings * @return: The longest common prefix ...
- [LintCode] Longest Common Prefix 最长共同前缀
Given k strings, find the longest common prefix (LCP). Have you met this question in a real intervie ...
- 14. Longest Common Prefix
题目: Write a function to find the longest common prefix string amongst an array of strings. Subscribe ...
- Leetcode Longest Common Prefix
Write a function to find the longest common prefix string amongst an array of strings. class Solutio ...
- [LeetCode] 14. Longest Common Prefix
Write a function to find the longest common prefix string amongst an array of strings. public class ...
- No.014:Longest Common Prefix
问题: Write a function to find the longest common prefix string amongst an array of strings. 官方难度: Eas ...
- No.014 Longest Common Prefix
14. Longest Common Prefix Total Accepted: 112204 Total Submissions: 385070 Difficulty: Easy Write a ...
随机推荐
- servlet执行流程
视频地址:http://www.imooc.com/video/5550 1-6 用户输入地址:localhost:8080/MyFirstServletDemo/index.jsp (My ...
- blocked file type by sharepoint 分类: Sharepoint 2015-07-05 07:45 6人阅读 评论(0) 收藏
o add or remove blocked file types by using Central Administration Verify that you have the followin ...
- 黑马程序员——OC语言 类和对象
Java培训.Android培训.iOS培训..Net培训.期待与您交流! (以下内容是对黑马苹果入学视频的个人知识点总结) (一)类 1)类的声明 代码编写 ①定义一个Car类,拥有2个属性:轮子数 ...
- js传url中文参数乱码问题
$("#btnKeyWord").click(function () { window.open("/Atraction/Atraction.aspx?keyword=& ...
- MAC上python+Eclipse+pydev环境搭建
转自:http://www.cnblogs.com/Bonker/p/3584707.html 本文重点介绍使用Eclipse+pydev插件来写Python代码, 以及在Mac上配置Eclipse ...
- 域环境下装SQL SERVER的一次惨痛经历
SQL SERVER 2008 R2 其实sql server不建议装在域环境下的,但sharepoint必须用域用户来连接.这本来也不是个什么大问题,但是,这一次相当的不顺利哦. 我有单独的域控,单 ...
- 实际项目中积累的一些关于事件的简单应用JS代码段(能力有限,不喜轻喷,23333)
1:鼠标移入移出显示另一张图片 var yuanquan_1 = document.getElementById("yuanquan_1" ); yuanquan_1. onmo ...
- 《JavaScript模式》第4章 函数
@by Ruth92(转载请注明出处) 第4章:函数 一.JavaScript 中函数的两个重要特征 函数是第一类对象,可以作为带有属性和方法的值以及参数进行传递: 函数提供了局部作用域,而其他大括号 ...
- Pylot压力测试(linux)
Pylot需要python2.5以上的版本,打开以后选择对应你的系统的版本,下载好之后双击安装. centOS5.5 系统版本python版本是2.4.3,所以要下载个2.5以上的. 1.下载Pyth ...
- redis windows
下载 redis windows版本 redis-server redis.windows.conf //cmd 命令 启动成功 E:\redis\Redis-x64-3.0.500>red ...