Skip to content

Commit ae7a508

Browse files
committed
Fix question 1048.
1 parent 3d581bf commit ae7a508

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

leetcode/medium/1048_longest_string_chain.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22

33
## Memoization with Recursion Solution
44

5-
- Runtime: O(N) * O(C^C) for worst case, O(N) + O(C^C) for best case
5+
- Runtime: O(NC) + O(C^C)
66
- Space: O(C)
77
- N = Number of words in list
88
- C = Longest character word
99

1010
We can come up with a recursive solution quite easily by removing each letter and calling the next recursion function on each newly formed word.
11-
However, this would equate to a run-time of O(C^C), since we have to do this N times, it would then be O(N) * O(C^C).
11+
However, this would equate to a run-time of O(C^C), since we have to do this N times, and each time we have to delete each character O(NC), it would then be O(NC) + O(C^C).
1212

1313
We can improve our run-time by using memoization, instead of redoing checks, we just check once for each path and save that result.
1414
So if we can only build a chain of 3 with 'abcd', if given 'abcde', when it comes to removing 'e', we don't need to check each character of 'abcd' again, instead just return 3.

0 commit comments

Comments
 (0)