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 ...
随机推荐
- 线程池框架executor
Eexecutor作为灵活且强大的异步执行框架,其支持多种不同类型的任务执行策略,提供了一种标准的方法将任务的提交过程和执行过程解耦开发,基于生产者-消费者模式,其提交任务的线程相当于生产者,执行任务 ...
- CATransition 实践
时间差不够,导致闪屏 CATransition *animation = [CATransition animation]; animation.delegate = self; animation. ...
- arcmap搜索脚本错误
C盘/windows/temp,将temp文件夹右键单击,选择属性>选择安全>编辑>AlL APPLICATION PACKAGES>确定>关闭,如是操作即可解决 在cu ...
- sqlite3 插入数据的时候,返回SQLITE_CONSTRAINT
sqlite3 插入数据的时候.返回SQLITE_CONSTRAINT 原因是:数据库的表的名字是纯数字. 大改这个原因太诡异了.创建的时候能够创建成功. 插入数据的时候就失败,由于表名是纯数字. 附 ...
- java容器HashMap原理
1.为什么需要HashMap 前面我们说了ArrayList和LinkedList,它们对容器内的对象都能实现增.删.改.查.遍历等操作, 并且对应不同的情况,我们可以选择不同的List,用以提高效率 ...
- byte[],bitmap,drawable之间的相互转换
Byte[]转Bitmap BitmapFactory.decodeByteArray(data, 0, data.length); Bitmap转Byte[] ByteArrayOutputStre ...
- List转换为字符串并添加分隔符
// 方法一: public String listToString(List list, char separator) { StringBuilder sb = new StringBuilder ...
- 伯努利分布、二项分布、Beta分布、多项分布和Dirichlet分布与他们之间的关系,以及在LDA中的应用
在看LDA的时候,遇到的数学公式分布有些多,因此在这里总结一下思路. 一.伯努利试验.伯努利过程与伯努利分布 先说一下什么是伯努利试验: 维基百科伯努利试验中: 伯努利试验(Bernoulli tri ...
- VMware vSphere中的HA工作原理介绍
http://blog.51cto.com/linkinsds/416738 HA全称High Availability.它是VMware的企业应用环境中用来保障企业级应用的不间断运行需求所产生的一个 ...
- jQuery事件命名空间多事件绑定自定义事件js 命名空间 javascript命名空间
http://blog.csdn.net/pigpigpig4587/article/details/24727791 jQuery事件命名空间 jQuery支持事件命名空间,以方便事件管理.例如,在 ...