LintCode题解之最长单词
2017-11-26 04:02
513 查看
这些一次遍历搞定的,套路无非都是在遍历的时候就记录数据的状态,然后根据遍历到的当前的数据的状态来修改最终结果,当遍历完了的时候结果也就确定了。
public class Solution { /* * @param dictionary: an array of strings * @return: an arraylist of strings */ public List<String> longestWords(String[] dictionary) { int maxLength = Integer.MIN_VALUE; List<String> resultList = new ArrayList<>(); for(String s : dictionary){ if(s.length()>maxLength){ maxLength = s.length(); resultList = new ArrayList<>(); resultList.add(s); }else if(s.length()==maxLength){ resultList.add(s); } } return resultList; } }
题目来源: http://www.lintcode.com/zh-cn/problem/longest-words/
相关文章推荐
- lintcode :最长单词
- lintcode&九章算法——Google 面试题 | 字典里面的最长单词 ? 待解决
- lintcode 133 最长单词
- lintcode ----最长单词
- lintcode python代码 422 最后一个单词长度
- lintcode:最长上升连续子序列
- lintcode python— 最长公共字符串
- Lintcode(5)-最长公共子串
- LintCode:M-最长无重复字符的子串
- Lintcode182 Delete Digits solution 题解
- lintcode longest-increasing-continuous-subsequence 最长上升连续子序列
- LintCode之最长回文串
- lintcode:最长上升子序列
- lintcode :longest common substring 最长公共子串
- LintCode--最长上升连续子序列
- lintcode :最长上升连续子序列
- Lintcode90 K Sum || solution 题解
- Lintcode—(5)最长公共子串
- lintcode---实现trie--单词的添加与查找
- lintcode-76-最长上升子序列