来源:力扣(LeetCode) 链接:https://leetcode-cn.com/problems/scramble-string 著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。 2. 解题 2.1 记忆化递归 按照长度 1 到 n-1 把 s1 , s2 切开,递归判断 注意用哈希表记录下来一些已经得到的结果,否则超时195 / 285 个通过测试用例 代...
https://leetcode.com/problems/sort-list/https://leetcode.com/problems/remove-linked-list-elements...
//Time Limit ExceededclassSolution {public:boolisScramble(strings1,strings2) {if(s1 == s2)returntrue;stringstr1 = s1, str2 =s2; sort(str1.begin(), str1.end()); sort(str2.begin(), str2.end());if(str1 != str2)returnfalse;for(inti =1; i < s1.size(); ++i) {strings11 =...
Given two numbers represented as strings,return multiplication of the numbers as a string. Note: The numbers can be arbitrarily large and are non-negative. 思路: 这是一道经常出现的面试题。竖式乘法怎么做的照搬就可以,注意看代码,用一个string搞定。 classSolution {public:stringmultiply(stringnum1,stri...
211 211. Add and Search Word - Data structure design.java Medium [Backtracking, Design, Trie] O(n) to search and to add word < O(mn), depends on the input. m = # of words Java 439 43 43. Multiply Strings.java Medium [Math, String] O(mn) O(mn) Java 440 621 621. Task Sched...
1616.Split-Two-Strings-to-Make-Palindrome (M+) 1754.Largest-Merge-Of-Two-Strings (M+) 1849.Splitting-a-String-Into-Descending-Consecutive-Values (M+) 2468.Split-Message-Based-on-Limit (H-) Abbreviation 408.Valid-Word-Abbreviation (M) 411.Minimum-Unique-Word-Abbreviation (H) 527.Word-Abbre...
A trie, or prefix tree, is a specialized tree data structure used to store a dynamic set of strings, where each node represents a common prefix shared by some strings. Tries are particularly useful for problems involving prefix matching, autocomplete features, and dictionary implementations.Key ope...
class Solution { public String addStrings(String num1, String num2) { int i = num1.length() - 1, j = num2.length() - 1, add = 0; StringBuffer ans = new StringBuffer(); while (i >= 0 || j >= 0 || add != 0) { int x = i >= 0 ? num1.charAt(i) - '0' : ...
Explanation: Buy on day 2 (price = 1) and sell on day 3 (price = 5), profit = 5-1 = 4. Then buy on day 4 (price = 3) and sell on day 5 (price = 6), profit = 6-3 = 3. Total profit is 4 + 3 = 7. Key Point: ...
一. 树 1)求二叉树的高度(Maximum Depth of Binary Tree)// LeetCode, Maximum Depth of Binary ...