LintCode: Longest Words
C++
class Solution {
public:
/**
* @param dictionary: a vector of strings
* @return: a vector of strings
*/
vector<string> longestWords(vector<string> &dictionary) {
// write your code here
if (dictionary.size() <= ) {
return dictionary;
}
vector<string> result;
int max_len = , cur_len;
for (int i=; i<dictionary.size(); i++) {
cur_len = dictionary[i].size();
if(cur_len < max_len) {
continue;
}
if(cur_len > max_len) {
result.clear();
max_len = cur_len;
}
result.push_back(dictionary[i]);
}
return result;
}
};
LintCode: Longest Words的更多相关文章
- LintCode Longest Common Substring
原题链接在这里:http://www.lintcode.com/en/problem/longest-common-substring/# 题目: Given two strings, find th ...
- LintCode Longest Common Subsequence
原题链接在这里:http://www.lintcode.com/en/problem/longest-common-subsequence/ 题目: Given two strings, find t ...
- [LintCode] Longest Increasing Continuous subsequence
http://www.lintcode.com/en/problem/longest-increasing-continuous-subsequence/# Give you an integer a ...
- Lintcode:Longest Common Subsequence 解题报告
Longest Common Subsequence 原题链接:http://lintcode.com/zh-cn/problem/longest-common-subsequence/ Given ...
- Lintcode: Longest Common Substring 解题报告
Longest Common Substring 原题链接: http://lintcode.com/zh-cn/problem/longest-common-substring/# Given tw ...
- [LintCode] Longest Common Prefix 最长共同前缀
Given k strings, find the longest common prefix (LCP). Have you met this question in a real intervie ...
- [LintCode] Longest Increasing Subsequence 最长递增子序列
Given a sequence of integers, find the longest increasing subsequence (LIS). You code should return ...
- [LintCode] Longest Substring Without Repeating Characters
Given a string, find the length of the longest substring without repeating characters. Have you met ...
- [LintCode] Longest Consecutive Sequence 求最长连续序列
Given an unsorted array of integers, find the length of the longest consecutive elements sequence. H ...
- [LintCode] Longest Increasing Continuous Subsequence 最长连续递增子序列
Give an integer array,find the longest increasing continuous subsequence in this array. An increasin ...
随机推荐
- IEnumerable是集合,IEnumerator是集合的迭代器
我们常用IEnumerable,却忽视IEnumerator.简单来说,IEnumerable是可以被循环遍历的集合,IEnumerator实施循环遍历. 接口分别是: public interfac ...
- jQuery把所有被选中的checkbox的某个属性值连接成字符串
有这样的一个需求:对于一组checkbox,当点击每个checkbox后,把当前处于选中状态的checkbox的某个属性值取出来连接成字符串,并以逗号分开. html部分: <input typ ...
- 【docker】【Gitlab】gitlab中clone项目时,IP地址是一串数字(内网Gitlab的IP地址不正确)的问题解决
首次在内网搭建Gitlab环境,在成功后在Gitlab上新建了一个项目. 然而在IDEA上clone项目时发现,项目地址如下: git@0096ce63c43f:root/jump.git 或者这样 ...
- 权力的游戏第七季/全集Game of Thrones迅雷下载
艾美及金球奖获奖HBO原创剧集<权力的游戏>第七季将于2016年夏天晚些时候开拍.新的一季共有七集,主要拍摄地为北爱尔兰,部分镜头也将在西班牙和冰岛取景.上映时间预计将略有推迟,至2017 ...
- versionCode溢出的问题
android应用的版本主要由versionCode和versionName来决定,android系统是根据versionCode来验证新的apk是否能安装.如果已安装高版本的应用,就无法使用覆盖安装 ...
- 对于多个button要在同一个监听器中实现自己的单击事件的方法小诀窍。
在网上的一些教程中往往是把一个button加入多个监听器,却非常少有人会把多个button在同一个监听器中去实现他们的单击事件,并且这杨的事实上是非常有用的,比方说在制作一个简单的计算器是就须要0-9 ...
- C# byte[]和文件FileStream相互转化
, pReadByte.Length); } catch { return false; ...
- 我的Java学习推荐书目
一直有这么个想法,列一下我个人认为在学习和使用Java过程中可以推荐一读的书籍,给初学者或者想深入的朋友一些建议,帮助成长.推荐的的都是我自己读过,也会推荐一些朋友读过并且口碑不错的书籍. 一.基础类 ...
- swift3.0:NSURLSession的使用
一.说明 NSURLSession是OC中的会话类,在Swift中变成URLSession类,它们的实现方式是一样的,下面的示例就Swift语法进行讲解和介绍. 二.介绍: URLSession 类支 ...
- SpringMVC request生命周期
When the request leaves the browser, it carries information about what the user is asking for. At ve ...