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

class Solution {
public:
string longestCommonPrefix(vector<string>& strs) {
int vSize = strs.size();
string result = "";
if(vSize == ) return result;
else if(vSize == ) return strs[]; result = strs[];
int i,j;
for(i = ; i < vSize; i++){
for(j = ; j < result.length() && j < strs[i].length(); j++){
if(strs[i][j] != result[j]) break;
}
result = result.substr(,j); //截取字符串
}
return result;
}
};

14.Longest Common Prefix (String)的更多相关文章

  1. [LeetCode][Python]14: Longest Common Prefix

    # -*- coding: utf8 -*-'''__author__ = 'dabay.wang@gmail.com'https://oj.leetcode.com/problems/longest ...

  2. 14. Longest Common Prefix【leetcode】

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

  3. C# 写 LeetCode easy #14 Longest Common Prefix

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

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

    Write a function to find the longest common prefix string amongst an array of strings. If there is n ...

  5. Leetcode 14. Longest Common Prefix(水)

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

  6. leetCode练题——14. Longest Common Prefix

    1.题目 14. Longest Common Prefix   Write a function to find the longest common prefix string amongst a ...

  7. 14. Longest Common Prefix

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

  8. [LeetCode] 14. Longest Common Prefix

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

  9. 【LeetCode】14. Longest Common Prefix 最长前缀子串

    题目: Write a function to find the longest common prefix string amongst an array of strings. 思路:求最长前缀子 ...

随机推荐

  1. How to get the full error stack trace of SharePoint

    博客地址 http://blog.csdn.net/foxdave SharePoint开发,怎么得到真实的详细错误信息. 大家在开发遇到页面报错需要提问的时候,先将详细错误信息获取到再提问,谢谢. ...

  2. Go安装一些第三方库

    原文链接:https://javasgl.github.io/go-get-golang-x-packages/ 侵权联系删除! go在go get 一些 package时候的会由于众所周知的原因而无 ...

  3. Sqlserver 按照时间段统计数据

    WITH t1 ( [hour], title ) , ' 0:00:00--- 1:00:00' UNION ALL , ' 1:00:00--- 2:00:00' UNION ALL , ' 2: ...

  4. Linux上jdk安装及环境变量设置

    1.jdk下载和安装 (1)http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html下载需 ...

  5. query更多的筛选用法

    比较操作符$eq : =  写法:db.class0.find({age:{$eq:18}},{name:1,_id:0}); 查找年龄等于18$lt :<$lte : <=$gt : & ...

  6. 51Nod 1081:子段求和(前缀和)

    1081 子段求和  基准时间限制:1 秒 空间限制:131072 KB 分值: 0 难度:基础题  收藏  关注 给出一个长度为N的数组,进行Q次查询,查询从第i个元素开始长度为l的子段所有元素之和 ...

  7. python 之 collections

    Python作为一个“内置电池”的编程语言,标准库里面拥有非常多好用的模块.比如今天想给大家 介绍的 collections 就是一个非常好的例子. 基本介绍 我们都知道,Python拥有一些内置的数 ...

  8. Packer 基本试用

    安装 使用mac 系统 https://www.packer.io/downloads.html 配置环境变量 可选 sudo nano ~/.bash_profile export PATH=$PA ...

  9. Android - 传统蓝牙通信聊天

    Android -传统蓝牙通信聊天 技术:java+Android4.4+jdk1.8 运行环境:Android4.4.Android7.0 概述 Android 传统蓝牙的使用,包括开关蓝牙.搜索设 ...

  10. oracle 查版本号

    oracle是强大的数据库,我们怎样看它的版本呢? 工具/原料 oracle 数据库, sqlplus 方法/步骤 首先进入sqlplus,cmd---plsql,登陆我们的用户,如:user/pas ...