Longest Common Prefix
Description:
Write a function to find the longest common prefix string amongst an array of strings.(最长公共字串)
Code:
string merge(string&str1, string&str2)
{
string result="";
int n = (str1.size()<=str2.size())?str1.size():str2.size();
for (int i = ; i < n; ++i)
{
if (str1[i]==str2[i])
result=result+str1[i];
else
return result;
}
return result;
}
string longestCommonPrefix(vector<string>& strs, int start, int end)
{
if (start < end)
{
int middle = (start+end)/;
string str1 = longestCommonPrefix(strs, start, middle);
if (str1=="")
return str1;
string str2 = longestCommonPrefix(strs, middle+, end);
if (str2=="")
return str2;
return merge(str1, str2);
}
else
return strs[start];
}
string longestCommonPrefix(vector<string>& strs) {
if (strs.size()==)
return "";
return longestCommonPrefix(strs,,strs.size()-);
}
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 ...
- 68. Longest Common Prefix
Longest Common Prefix Write a function to find the longest common prefix string amongst an array of ...
- No.014 Longest Common Prefix
14. Longest Common Prefix Total Accepted: 112204 Total Submissions: 385070 Difficulty: Easy Write a ...
随机推荐
- 进程外session
进程外session A SqlServer 1.管理员身份运行cmd 2.更换目录 cd c:\Windows\Microsoft.NET\Framework\v4.0.30319> 3. ...
- 【转】解决svn Authorization failed错误
转载地址:http://blog.sina.com.cn/s/blog_4b93170a0100leb2.html 出现该问题基本都是三个配置文件的问题,下面把这个文件列出来 svnserve.con ...
- git status message - Your branch is ahead of origin/master by X commits
git reset --hard origin/master git status FAQ: When I issue the "git status" command, I se ...
- 网站性能优化之CSS无图片技术:三角形
1.使用CSS无图片技术,可以总结得到以下三个优点: 减少请求资源的大小: 减少http的请求个数: 提高可维护性. 一.CSS无图片技术,微博中有哪些实际应用呢? 通过上面的展示,我们可以看到,无图 ...
- EasyUI 我的第一个窗口
建立窗口时很简单的,我们建立DIV标记: <div id="win" class="easyui-window" title="My Windo ...
- 2016年11月3日 星期四 --出埃及记 Exodus 19:19
2016年11月3日 星期四 --出埃及记 Exodus 19:19 and the sound of the trumpet grew louder and louder. Then Moses s ...
- Linux用户应知应会的7个‘ls’命令的独特技巧
在前面我们系列报道的两篇文章中,我们已经涵盖了关于‘ls’命令的绝大多数内容.本文时‘ls命令’系列的最后一部分.如果你还没有读过该系列的其它两篇文章,你可以访问下面的链接. Linux中的15个基本 ...
- liftover的使用/用法
Lift genome positions Genome positions are best represented in BED format. UCSC provides tools to co ...
- github 修改fork的代码之后如何提交代码并pull request
官方的解释还是有点模糊,我是参照这篇文章来的. http://www.linuxidc.com/Linux/2012-12/76922.htm 关于Git的版本管理的原理,我是从这篇文章里面学习的. ...
- XSS技巧综合
这周六会在公司分享经验和技巧,把自己的和网上的一些技巧来综合写一些,方便大家和自己: 普通的XSS,储存,反射,DOM 形成的无外乎就是输出点在html标签之间,html属性之间,成为JS代码,称为C ...