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 ...
随机推荐
- IP组播
1 IP组播基础 IP组播技术有效地解决了单点发送.多点接收的问题.组播源只发送一份数据,被传递的信息在距组播源尽可能远的网络节点才开始被复制和分发,并且只发送给需要该信息的接收者. 说明: 本章 ...
- 存储过程参数CHAR传过来null导致超时.
调用的时候不要传NULL,可以传 '' ALTER PROCEDURE [dbo].[up_UC_GetUCExecuteEPList] @Code VARCHAR(3) ,--ch ...
- NOIP2016 酱油记
2016.11.17 考试前最后一个周四.然而我仍旧蒟蒻... 2016.11.18 周五,上午自家开车跑到晋城,中午12点到宾馆.下午4点去机房试机,先写了个线性筛,结果c++报错!?重开机,写个a ...
- 【未解决】centos 6.4 xen4.2 在关机的时候很慢
centos xen 在关机的时候 下面的关闭DomUs虚拟机 耗时很长... stopping xenconsoled daemon: [OK] sending shutdown to all Do ...
- swift:简单使用翻页控制器UIPageViewController
一.小叙 UIPageViewController是一个实现图书阅读的控制器,使用它可以设置书脊位置.单双页.过渡效果等,它是通过代理的方式来实现翻页,也即上一页.下一页.最终这个UIPageView ...
- go语言之进阶篇 channel介绍
1.channel介绍 和map类似,channel也一个对应make创建的底层数据结构的引用. 当我们复制一个channel或用于函数参数传递时,我们只是拷贝了一个channel引用,因此调用者何被 ...
- Java奇淫巧技之Lombok
http://blog.csdn.net/ghsau/article/details/52334762
- WINDOWS 逻辑坐标 设备坐标 屏幕坐标 客户区坐标
转自:http://blog.csdn.net/lovesunshine2008/article/details/4048158 设置坐标映射 (1)Windows坐标系统 Windows坐标系 ...
- Android -- com.android.providers.media,external.db
external.db android是管理多媒体文件(音频.视频.图片)的信息是在/data/data/com.android.providers.media下的数据库文件external.db. ...
- 转:无监督特征学习——Unsupervised feature learning and deep learning
http://blog.csdn.net/abcjennifer/article/details/7804962 无监督学习近年来很热,先后应用于computer vision, audio clas ...