LeetCode知识点总结 - 524
LeetCode 524. Longest Word in Dictionary through Deleting考点难度ArrayMedium题目Given a string s and a string array dictionary, return the longest string in the dictionary that can be formed by deleting some of the given string characters. If there is more than one possible result, return the longest word with the smallest lexicographical order. If there is no possible result, return the empty string.思路Check every word dictWord in the dictionary:Check 1: dictWord is a subsequence of sCheck 2: only consider words that are LONGER or SAME LENGTH as current longestTwo cases to update answer:1… New word is LONGER than old longest, OR2. Same length BUT lex order is SMALLER (e.g., “apple” “apply”)答案classSolution{publicintfib(intN){if(N1)returnN;inta0,b1;while(N--1){intsumab;ab;bsum;}returnb;}}
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/2463356.html
如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!