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的更多相关文章

  1. [LeetCode] Longest Common Prefix 最长共同前缀

    Write a function to find the longest common prefix string amongst an array of strings. 这道题让我们求一系列字符串 ...

  2. 【leetcode】Longest Common Prefix

    题目简述: Write a function to find the longest common prefix string amongst an array of strings. 解题思路: c ...

  3. LintCode 78:Longest Common Prefix

      public class Solution { /** * @param strs: A list of strings * @return: The longest common prefix ...

  4. [LintCode] Longest Common Prefix 最长共同前缀

    Given k strings, find the longest common prefix (LCP). Have you met this question in a real intervie ...

  5. 14. Longest Common Prefix

    题目: Write a function to find the longest common prefix string amongst an array of strings. Subscribe ...

  6. Leetcode Longest Common Prefix

    Write a function to find the longest common prefix string amongst an array of strings. class Solutio ...

  7. [LeetCode] 14. Longest Common Prefix

    Write a function to find the longest common prefix string amongst an array of strings. public class ...

  8. No.014:Longest Common Prefix

    问题: Write a function to find the longest common prefix string amongst an array of strings. 官方难度: Eas ...

  9. 68. Longest Common Prefix

    Longest Common Prefix Write a function to find the longest common prefix string amongst an array of ...

  10. No.014 Longest Common Prefix

    14. Longest Common Prefix Total Accepted: 112204 Total Submissions: 385070 Difficulty: Easy Write a ...

随机推荐

  1. git 基本命令

    (命令总结内容来自 博客园  圣骑士Wind的博客) git init      在本地新建一个repo,进入一个项目目录,执行git init,会初始化一个repo,并在当前文件夹下创建一个.git ...

  2. nginx安装后出现502 Bad Gateway 错误解决办法

    1. 打开php-fpm.conf 2.将lisen值修改为 listen = 127.0.0.1:9000 并保存 3.重启服务/etc/init.d/php-fpm restart

  3. java 反编译和文档生成器

    挺有趣的东西. 代码在上一篇中有. 反编译器javap.exe javadoc.exe制作源文件类结构的html格式文档

  4. Spring声明式事务管理与配置详解

    转载:http://www.cnblogs.com/hellojava/archive/2012/11/21/2780694.html 1.Spring声明式事务配置的五种方式 前段时间对Spring ...

  5. 批发网加盟页面轮播Jquery jcarousellite插件效果

    Jquery jcarousellite 插件的好处 其中: 参数说明: btnPrev     string 上一个按钮的class名, 比如  btnPrev: ".prev" ...

  6. html 标签学习

    form 属性 定义和用法 enctype 属性规定在发送到服务器之前应该如何对表单数据进行编码. 默认地,表单数据会编码为 "application/x-www-form-urlencod ...

  7. Struts2框架的运行流程

    Struts2的运行流程 1.浏览器发送请求到控制器(如Struts2中的核心控制器StrutsPrepareAndExecuteFilter): 2.控制器调用Action的execute方法: 3 ...

  8. 【Unity3D游戏开发】性能优化之spine提高80~90%的效率 (三一)

    Spine效率低 Unity项目加载spine动画,经常会出现卡顿的情况,如游戏中瞬间播放一个动画,打开一个带spine动画的界面.尤其是SkeletonRenderer.Awake时,会瞬间出现大量 ...

  9. c++ socket 客户端库 socks5 客户端 RudeSocket™ Open Source C++ Socket Library

    介绍 一个c++ socket 客户端库 http://www.rudeserver.com/socket/index.html The RudeSocket™ Open Source C++ Soc ...

  10. Python使用requirements.txt安装类库

    摘要:我们为何要应用requirements.txt呢? 首要应用目标: 任何 运用顺序 平常 须要设置装置 所需并 依附 一组类库去知足 事情请求 . 请求 文件 是 指定 战 一次性 装置 包 的 ...