使用字典,降低查找的复杂度.使用list会超时. class Solution: def nextWordsList(self, word, wordDict): res_list = [] for i in range(len(word)): for j in string.ascii_lowercase: new_word = list(word) if j != word[i]: new_word[i] = j new_word = ''.join(new_word) if new_wor…
刷题链接:https://leetcode-cn.com/explore/ 根据leetcode的探索栏目,八月份一直在上面进行刷题.发现算法题真的好难,真-计算机思维. 核心是将现实问题转化为计算机能够处理的计算问题.而这些计算问题都是通过逻辑分析来解决的. 因此逻辑-分析能力就是计算机思维的核心能力.比如将一个数组的增删改查,是通过逻辑中的 if -else while 这些基本语句构成的. 引用左神的算法刷题方法:“ 第一阶段:对于某一个具体的算法,首先要搞清楚这个算法解决的问…
Given a list of words (without duplicates), please write a program that returns all concatenated words in the given list of words. A concatenated word is defined as a string that is comprised entirely of at least two shorter words in the given array.…
Given a set of words (without duplicates), find all word squares you can build from them. A sequence of words forms a valid word square if the kth row and column read the exact same string, where 0 ≤ k < max(numRows, numColumns). For example, the wor…
Given a sequence of words, check whether it forms a valid word square. A sequence of words forms a valid word square if the kth row and column read the exact same string, where 0 ≤k < max(numRows, numColumns). Note: The number of words given is at le…
Given a non-empty string s and an abbreviation abbr, return whether the string matches with the given abbreviation. A string such as "word" contains only the following valid abbreviations: ["word", "1ord", "w1rd", &…
Given a string array words, find the maximum value of length(word[i]) * length(word[j]) where the two words do not share common letters. You may assume that each word will contain only lower case letters. If no such two words exist, return 0. Example…
An abbreviation of a word follows the form <first letter><number><last letter>. Below are some examples of word abbreviations: a) it --> it (no abbreviation) 1 b) d|o|g --> d1g 1 1 1 1---5----0----5--8 c) i|nternationalizatio|n --&…