//日积月累,水滴石穿
class Solution {
public:
string longestCommonPrefix(vector<string>& strs) {
if (strs.empty()) return ""; //必须要加空的特判
string res = "";
for(int i=;i < strs[].size();i++){
for(int j=;j < strs.size();j++){
if(i >= strs[j].size() || strs[j][i] != strs[][i])
return res;
}
res.push_back(strs[][i]);
}
return res;
}
};
int main()
{
string s[] = {"abca","abc"}; //内容为string的vector
vector<string> n;
n.insert(n.begin(),s,s+); Solution a;
cout << a.longestCommonPrefix(n) << endl; return ;
}

_

Leetcode 12的更多相关文章

  1. leetcode 12题 数字转罗马数字

    leetcode 12题 数字转罗马数字 答案一:我的代码 代码本地运行完全正确,在线运行出错 class Solution { public: string intToRoman(int num) ...

  2. [LeetCode] 12. Integer to Roman 整数转化成罗马数字

    Roman numerals are represented by seven different symbols: I, V, X, L, C, D and M. Symbol Value I 1 ...

  3. Leetcode 12,452,455-贪心算法

    Leetcode第12题,整数转罗马数字,难度中等 整个题目比较好理解,难度也不大,就算不过脑子,用一串if也基本上可以解决问题,比如 /** 执行用时:6ms,在所有 Java 提交中击败了52.6 ...

  4. Java实现 LeetCode 12 整数转罗马数字

    12. 整数转罗马数字 罗马数字包含以下七种字符: I, V, X, L,C,D 和 M. 字符 数值 I 1 V 5 X 10 L 50 C 100 D 500 M 1000 例如, 罗马数字 2 ...

  5. Leetcode 12——Integer to Roman

    12.Integer to Roman Given an integer, convert it to a roman numeral. Input is guaranteed to be withi ...

  6. [LeetCode] 12,13 整数和罗马数互转

    12. 整数转罗马数字 题目链接:https://leetcode-cn.com/problems/integer-to-roman/ 题目描述: 罗马数字包含以下七种字符: I, V, X, L,C ...

  7. LeetCode(12. 整数转罗马数字)

    问题描述 罗马数字包含以下七种字符: I, V, X, L,C,D 和 M. 字符 数值 I 1 V 5 X 10 L 50 C 100 D 500 M 1000 例如, 罗马数字 2 写做 II , ...

  8. LeetCode——12. Integer to Roman

    一.题目链接:https://leetcode.com/problems/integer-to-roman/ 二.题目大意: 给定一个整数,返回它的罗马数字的形式. 三.题解: 要想做出这道题目,首先 ...

  9. [leetcode 12] Inter to Roman

    1 题目: Given an integer, convert it to a roman numeral. Input is guaranteed to be within the range fr ...

  10. LeetCode 12 Integer to Roman (整数转罗马数字)

    题目链接: https://leetcode.com/problems/integer-to-roman/?tab=Description   String M[] = {"", ...

随机推荐

  1. scrapy爬虫系列之五--CrawlSpider的使用

    功能点:CrawlSpider的基本使用 爬取网站:保监会 主要代码: cf.py # -*- coding: utf-8 -*- import scrapy from scrapy.linkextr ...

  2. float和double

    Java中,使用Float.floatToRawIntBits()函数获得一个单精度浮点数的IEEE 754 表示,例如: float fNumber = -5; //获得一个单精度浮点数的IEEE ...

  3. SprinBoot CLI 安装(Mac版)

    1. 安装 HomeBrew /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/instal ...

  4. spring boot由浅入深(二)spring boot基本命令及操作

    一 spring常见注解 @RestController和@RequestMapping说明: @RestController.这被称为一个构造型(stereotype)注解.它为阅读代码的人们提供建 ...

  5. web前端开发http-server

    windows环境下需先安装npm 安装 npm install -g http-server http-server -a hostip -p port

  6. 【JEECG技术博文】JEECG表单配置-树形表单

    表单配置支持树型表单了,详细效果例如以下图:

  7. saltstack master minion 配置文件

    Master端的配置是修改/etc/salt下master配置文件.以下是Master端常用的配置. interface: 指定bind 的地址(默认为0.0.0.0) publish_port: 指 ...

  8. How To Mine Bitcoins 比特币挖矿

    linux 下查看 gpu 的信息: sudo lshw -C display windows下查看cuda信息:In directory C:\Program Files\NVIDIA Corpor ...

  9. mydumper原理介绍

      mydumper的安装:http://www.cnblogs.com/lizhi221/p/7010174.html   mydumper介绍   MySQL自身的mysqldump工具支持单线程 ...

  10. CNN学习笔记:批标准化

    CNN学习笔记:批标准化 Batch Normalization Batch Normalization, 批标准化, 是将分散的数据统一的一种做法, 也是优化神经网络的一种方法. 在神经网络的训练过 ...