524. Longest Word in Dictionary through Deleting【Medium】【删除后得到的字典中的最长单词】
Given a string and a string dictionary, find the longest string in the dictionary that can be formed by deleting some characters of the given string. If there are more than one possible results, return the longest word with the smallest lexicographical order. If there is no possible result, return the empty string.
Example 1:
Input:
s = "abpcplea", d = ["ale","apple","monkey","plea"] Output:
"apple"
Example 2:
Input:
s = "abpcplea", d = ["a","b","c"] Output:
"a"
Note:
- All the strings in the input will only contain lower-case letters.
 - The size of the dictionary won't exceed 1,000.
 - The length of all the strings in the input won't exceed 1,000.
 
class Solution {
   public String findLongestWord(String s, List<String> d) {
    String res = "";
    for(String str: d){
            if(check(s, str) && (str.length() > res.length()
                              || str.length() == res.length() && res.compareTo(str) > 0 ))
                res = str;
        }
        return res;
    }
   private boolean check(String s, String str) {
       int j = 0;
       for(int i = 0; i < s.length() && j < str.length(); i++) {
           if(s.charAt(i) == str.charAt(j)) {
               j++;
           }
       }
       return j == str.length();
   }
}

524. Longest Word in Dictionary through Deleting【Medium】【删除后得到的字典中的最长单词】的更多相关文章
- leetcode 524. Longest Word in Dictionary through Deleting 通过删除字母匹配到字典里最长单词
		
一.题目大意 https://leetcode.cn/problems/longest-word-in-dictionary-through-deleting 给你一个字符串 s 和一个字符串数组 d ...
 - [LeetCode] Longest Word in Dictionary through Deleting 删除后得到的字典中的最长单词
		
Given a string and a string dictionary, find the longest string in the dictionary that can be formed ...
 - #Leetcode# 524. Longest Word in Dictionary through Deleting
		
https://leetcode.com/problems/longest-word-in-dictionary-through-deleting/ Given a string and a stri ...
 - 524. Longest Word in Dictionary through Deleting
		
Given a string and a string dictionary, find the longest string in the dictionary that can be formed ...
 - Longest Word in Dictionary through Deleting - LeetCode
		
目录 题目链接 注意点 解法 小结 题目链接 Longest Word in Dictionary through Deleting - LeetCode 注意点 长度一样的字符串要按字典序返回较小的 ...
 - 【LeetCode】Longest Word in Dictionary through Deleting 解题报告
		
[LeetCode]Longest Word in Dictionary through Deleting 解题报告 标签(空格分隔): LeetCode 题目地址:https://leetcode. ...
 - [LeetCode] Longest Word in Dictionary 字典中的最长单词
		
Given a list of strings words representing an English Dictionary, find the longest word in words tha ...
 - [Swift]LeetCode524. 通过删除字母匹配到字典里最长单词 | Longest Word in Dictionary through Deleting
		
Given a string and a string dictionary, find the longest string in the dictionary that can be formed ...
 - LeetCode——Longest Word in Dictionary through Deleting
		
1. Question Given a string and a string dictionary, find the longest string in the dictionary that c ...
 
随机推荐
- Win7 64位系统下 Retional rose 2003 安装及破解
			
网上关于Retional rose 2003安装和破解的文章比较多,这里,我结合自己的亲身体验,和大家分享一下win7 旗舰版 64位系统下Retional rose 2003(下面简称rose200 ...
 - 任何用户密码都能以sysdba角色登入
			
这是因为在安装Oracle的时候默认是使用了操作系统验证: 数据库用sysdba登录的验证有两种方式,一种是通过os认证,一种是通过密码文件验证:登录方式有两种,一种是在数据库主机直接登录(用os认证 ...
 - vijos  1471 线性DP+贪心
			
描述 Orz教主的成员为教主建了一个游乐场,在教主的规划下,游乐场有一排n个弹性无敌的跳跃装置,它们都朝着一个方向,对着一个巨大的湖,当人踩上去装置可以带你去这个方向无限远的地方,享受飞行的乐趣.但是 ...
 - 【hdu1828/poj1177】线段树求矩形周长并
			
题意如图 题解:这题非常类似与矩形面积并,也是维护一个被覆盖了一次以上的线段总长. 但是周长要算新出现的,所以每次都要和上一次做差求绝对值. x轴做一遍,y轴做一遍. 但是有个问题:矩形边界重合的时候 ...
 - Piggy-Bank(多重背包+一维和二维通过方式)
			
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1114 题面: Problem Description Before ACM can do anythi ...
 - JQuery-Ajax后台提交数据与获取数据 Java代码
			
function jqajax(){ var urlName = $("#urlName").val(); var urla = $("#url").val() ...
 - C#  获取一段日期内的工作日
			
/// <summary> /// 根据指定时间段计算工作日天数 /// </summary> /// <param name="firstDay"& ...
 - perl模拟登录(1)
			
use WWW::Mechanize; my $ua = WWW::Mechanize->new(); $ua->post('http://localhost/dvwa/DVWA-mast ...
 - WmiPrvSE.exe进程(WMI Provider Host)不能删除
			
WmiPrvSE.exe进程基本信息:程序厂商:微软® Microsoft Corp.进程描述:WMI Provider Host进程属性:Windows系统进程使用网络:是的启动情况:触发启动 来历 ...
 - [How to]Cloudera manager 离线安装手册
			
2016-01-1910:54:05 增加kafka 1.简介 本文介绍在离线环境下安装Cloudera manager和简单使用方法 2.环境 OS:CentOS 6.7 Cloudera man ...