LeetCode题解之 Longest Common Prefix
1、题目描述

2、问题分析
直接使用循环解决问题
3、代码
string longestCommonPrefix(vector<string>& strs) {
string res = "";
if(strs.size() == )
return res;
bool isFull = true;
bool isEqual = true;
int pre = ;
while(isFull && isEqual){
vector<string>::iterator it = strs.begin();
if( pre == (*it).size() ){
isFull = false;
break;
}
string s1 = (*it).substr(pre,);
for( it = strs.begin() + ; it != strs.end(); ++it ){
if( (*it).substr(pre,) != s1 ){
isEqual = false;
break;
}
if( pre == (*it).size() ){
isFull = false;
break;
}
}
if( isEqual && isFull )
res += s1;
pre++;
}
return res;
}
LeetCode题解之 Longest Common Prefix的更多相关文章
- LeetCode题解(14)--Longest Common Prefix
https://leetcode.com/problems/longest-common-prefix/ 原题: Write a function to find the longest common ...
- 《LeetBook》leetcode题解(14):Longest Common Prefix[E]
我现在在做一个叫<leetbook>的免费开源书项目,力求提供最易懂的中文思路,目前把解题思路都同步更新到gitbook上了,需要的同学可以去看看 书的地址:https://hk029.g ...
- 【LeetCode】14. Longest Common Prefix 最长公共前缀
作者: 负雪明烛 id: fuxuemingzhu 个人博客:http://fuxuemingzhu.cn/ 个人公众号:负雪明烛 本文关键词:prefix, 公共前缀,题解,leetcode, 力扣 ...
- [LeetCode][Python]14: Longest Common Prefix
# -*- coding: utf8 -*-'''__author__ = 'dabay.wang@gmail.com'https://oj.leetcode.com/problems/longest ...
- 【一天一道LeetCode】#14 Longest Common Prefix
一天一道LeetCode系列 (一)题目: Write a function to find the longest common prefix string amongst an array of ...
- 【LeetCode】014. Longest Common Prefix
Write a function to find the longest common prefix string amongst an array of strings. 题解: 简单的暴力遍历解决 ...
- # Leetcode 14:Longest Common Prefix 最长公共前缀
公众号:爱写bug Write a function to find the longest common prefix string amongst an array of strings. If ...
- 【LeetCode】14. Longest Common Prefix 最长前缀子串
题目: Write a function to find the longest common prefix string amongst an array of strings. 思路:求最长前缀子 ...
- 【LeetCode】14 - Longest Common Prefix
Write a function to find the longest common prefix string amongst an array of strings. Solution: cla ...
随机推荐
- NIO的Buffer&Channel&Selector
java的NIO和AIO Buffer position.limit.capacity 初始化 Buffer 填充 Buffer 提取 Buffer 中的值 mark() & reset() ...
- 基数估算HyperLogLog
HyperLogLog HyperLogLog 可以接受多个元素作为输入,并给出输入元素的基数估算值: • 基数:集合中不同元素的数量.比如 {'apple', 'banana', 'cherry', ...
- 【JS】for in循环对象,hasOwnProperty()的作用
var obj = { name:"echolun", age:", sex:"male" }, objName=[], //用来装对象属性名 obj ...
- python的Web框架,Django模板标签及模板的继承
模板标签 在传递数据的时候,会有大量的数据展示在浏览器上,而数据会是动态变化的,在html的编写中,数据也是需要动态的,而不能是写死的,如果动态展示呢. 给定的例子数据 views传递数据给html ...
- [转]Microsoft SQL SERVER 2008 R2 REPORT SERVICE 匿名登录
本文转自:https://www.cnblogs.com/Zouzhe/p/5736070.html SQL SERVER 2008 R2 是微软目前最新的数据库版本,在之前的SQL SERVER 2 ...
- T-SQL建索引
USE database GO ------------开始----------- ALTER TABLE [name] DROP CONSTRAINT 主键约束 ----删除主键约束 IF ...
- C#微信小程序服务端获取用户解密信息
using AIOWeb.Models; using Newtonsoft.Json; using Newtonsoft.Json.Linq; using System; using System.C ...
- 选择ORACLE数据库字符集
如何选择数据库的字符集是一个有争议的话题,字符集本身涉及的范围很广,它与应用程序.客户的本地环境.操作系统.服务器等关系很密切,因此要做出合适的 选择,需要明白这些因素之间的关系.另外对字符集的基本概 ...
- 无法将类型“System.Collections.Generic.List<anonymous type:string ClassID,string ClsssName>”隐式转换为“System.Collections.Generic.List<Ecology.Model.EnergyFlowGraph>”
无法将类型“System.Collections.Generic.List<anonymous type:string ClassID,string ClsssName>”隐式转换为“Sy ...
- Retrofit2+Rxjava+OkHttp的使用和网络请求
Retrofit2+Rxjava+OkHttp的使用和网络请求 https://blog.csdn.net/huandroid/article/details/79883895 加入Rxjava 如果 ...