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的更多相关文章

  1. LintCode Longest Common Substring

    原题链接在这里:http://www.lintcode.com/en/problem/longest-common-substring/# 题目: Given two strings, find th ...

  2. LintCode Longest Common Subsequence

    原题链接在这里:http://www.lintcode.com/en/problem/longest-common-subsequence/ 题目: Given two strings, find t ...

  3. [LintCode] Longest Increasing Continuous subsequence

    http://www.lintcode.com/en/problem/longest-increasing-continuous-subsequence/# Give you an integer a ...

  4. Lintcode:Longest Common Subsequence 解题报告

    Longest Common Subsequence 原题链接:http://lintcode.com/zh-cn/problem/longest-common-subsequence/ Given ...

  5. Lintcode: Longest Common Substring 解题报告

    Longest Common Substring 原题链接: http://lintcode.com/zh-cn/problem/longest-common-substring/# Given tw ...

  6. [LintCode] Longest Common Prefix 最长共同前缀

    Given k strings, find the longest common prefix (LCP). Have you met this question in a real intervie ...

  7. [LintCode] Longest Increasing Subsequence 最长递增子序列

    Given a sequence of integers, find the longest increasing subsequence (LIS). You code should return ...

  8. [LintCode] Longest Substring Without Repeating Characters

    Given a string, find the length of the longest substring without repeating characters. Have you met ...

  9. [LintCode] Longest Consecutive Sequence 求最长连续序列

    Given an unsorted array of integers, find the length of the longest consecutive elements sequence. H ...

  10. [LintCode] Longest Increasing Continuous Subsequence 最长连续递增子序列

    Give an integer array,find the longest increasing continuous subsequence in this array. An increasin ...

随机推荐

  1. C#编程(七十)----------dynamic类型

    原文链接 : http://blog.csdn.net/shanyongxu/article/details/47296033 dynamic类型 C#新增了dynamic关键字,正是因为这一个小小的 ...

  2. C#编程(六十五)----------表达式树

    表达式树 以前没听过表达式树,只听过表达式,而且听过Lambda表达式,首先介绍一下.NET里表达式树的核心概念:讲代码作为数据,他将一些代码表示为一个对象树,树中的每个节点本身都是一个表达式,不同的 ...

  3. 在NDK C++线程中如何调用JAVA API

    from://http://www.eoeandroid.com/thread-150995-1-1.html 在NDK中创建的线程中, 只允许调用静态的Java API. 当在线程中调用env-&g ...

  4. 本地docker搭建gitlab, 并配置ldap认证

    基于Docker在Mac OS X系统中的部署和设置GitLab的具体过程如下:   1. 安装Docker for Mac (参见https://docs.docker.com/docker-for ...

  5. mysql中文显示问号,不能识别中文的解决方案

    到后台mysql中查看是问号. 并不能显示出中文,初步判定是编码的问题. 我们利用 show variables like'character_set_%'; 与 show variables lik ...

  6. spring boot 之@JsonView 简单介绍

    @JsonView是jackson json中的一个注解,spring webmvc也支持这个注解. 这个注解的作用就是控制输入输出后的json. 假设我们有一个用户类,其中包含用户名和密码,一般情况 ...

  7. http链接的性能测试工具httping

    安装:MAC环境下使用brew进行安装      brew  install  httping 使用参数: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 1 ...

  8. Java中CAS详解

    在JDK 5之前Java语言是靠synchronized关键字保证同步的,这会导致有锁 锁机制存在以下问题: (1)在多线程竞争下,加锁.释放锁会导致比较多的上下文切换和调度延时,引起性能问题. (2 ...

  9. C#里,如何模拟DataGridView里的一个Cell的Click事件。

    //假设dgv是一个DataGridView. //我要点击第3行的第二个cell. //当然,要有一个点击事件.假设dgv_CellClick是那个点击事件. dgv_CellClick(dgv,  ...

  10. Java命令学习系列(四)——jstat

    jstat(JVM Statistics Monitoring Tool)是用于监控虚拟机各种运行状态信息的命令行工具.他可以显示本地或远程虚拟机进程中的类装载.内存.垃圾收集.JIT编译等运行数据, ...