524. Longest Word in Dictionary through Deleting
来源:互联网 发布:excel单元格数据的分列 编辑:程序博客网 时间:2024/05/16 23:43
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.
public class Solution { public String findLongestWord(String s, List<String> d) { String res = ""; char[] ch = s.toCharArray(); for (String str: d) { int i = 0, j = 0; char[] dic = str.toCharArray(); while (i < ch.length && j < dic.length) { if (ch[i] == dic[j]) { i ++; j ++; } else { i ++; } if (j == dic.length) { if (j > res.length() || (j == res.length() && res.charAt(0) > dic[0])) { res = str; } } } } return res; }}
0 0
- 524. Longest Word in Dictionary through Deleting
- 524. Longest Word in Dictionary through Deleting
- 524. Longest Word in Dictionary through Deleting
- 524. Longest Word in Dictionary through Deleting
- 524. Longest Word in Dictionary through Deleting
- 524. Longest Word in Dictionary through Deleting
- 524. Longest Word in Dictionary through Deleting
- 524. Longest Word in Dictionary through Deleting
- 524. Longest Word in Dictionary through Deleting
- 524. Longest Word in Dictionary through Deleting
- 524. Longest Word in Dictionary through Deleting
- 524. Longest Word in Dictionary through Deleting
- Longest Word in Dictionary through Deleting
- leetcode524~Longest Word in Dictionary through Deleting
- [LeetCode] Longest Word in Dictionary through Deleting
- Longest Word in Dictionary through Deleting
- Longest Word in Dictionary through Deleting
- Leetcode-524. Longest Word in Dictionary through Deleting
- 网络编程Socket的阻塞和非阻塞IO
- Python安装scrapy库过程中出现“ Failed building wheel for xxx”的解决办法
- centos7部署gitlab服务器问题汇总
- centos下安装mysql5.5
- 客户端Socket
- 524. Longest Word in Dictionary through Deleting
- 射随器负半周削波问题
- spring配置datasource的4种方式
- 遇到一个很有趣的问题,while(ture)或者for循环出现异常,继续执行还是跳出异常
- 在Ubuntu上创建Git仓库并上传到GitHub
- js 浅拷贝与深拷贝
- Spring中bean的init和destroy方法讲解
- request.getCharacterEncoding() 的返回值为什么会是null
- MapReduce-------------Win7下使用Eclipse玩转Linux端的MapReduce