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 ...
随机推荐
- [BIM]案例
以下是中建三局BIM小组的项目,用以参考: BIM协同设计与质量控制 现实建筑物实体都是以三维空间状态存在,若用三维设计表达更具有优势.如复杂管综设计,一般情况下,二维AutoCAD设计是在建筑.结构 ...
- 【转】使用JDK自带jvisualvm监控tomcat
转载地址: http://my.oschina.net/kone/blog/157239 jdk自带有个jvisualvm工具.该工具是用来监控java运行程序的cpu.内存.线程等的使用情况.并且使 ...
- YTU 3013: 皇后问题(递归)
3013: 皇后问题(递归) 时间限制: 1 Sec 内存限制: 128 MB 提交: 2 解决: 2 题目描述 编写一个函数,求解皇后问题:在n*n的方格棋盘上,放置n个皇后,要求每个皇后不同行 ...
- JVM的classloader(转)
Java中一共有四个类加载器,之所以叫类加载器,是程序要用到某个类的时候,要用类加载器载入内存. 这四个类加载器分别为:Bootstrap ClassLoader.Extension Class ...
- Unity-Animator深入系列---录制与回放
回到 Animator深入系列总目录 Animator自带了简单的动画录制,回放功能.但可惜的是不支持持久化的数据输出.因而不能作为录像保存 不过这种可以作为竞速,格斗类游戏在结束时经常出现的游戏回放 ...
- centos 6.5源码编译安装subversion 1.8.10
一.简介 CentOS 6.5的yum源可以安装的SVN客户端版本太低了,1.6.11,所以需要升级到1.8.10,而官网有没有找到1.8.10的安装包,只能选择源码编译安装. 二.安装步骤 参考官网 ...
- phpcms 04
首页index.html 首页头条推荐 <div class="col-left"> <div class="news-hot"> &l ...
- linux网络基础--学习笔记
- Jquery 内容简介
内容简介 内容简介 • 什么是Jquery • 万能的选择器 • 管理jQuery包装集 • 使用jQuery操作元素的属性与样式 • 事件与事件对象 • jQuery中的Ajax • jQuery ...
- bouncycastle创建csr
public static void main(String[] args) { String subjectDN = "CN=duwenlei"; String algorith ...