Skip to content

Commit c848b34

Browse files
author
Joseph Luce
authored
Update 1048_longest_string_chain.md
1 parent ae7a508 commit c848b34

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

leetcode/medium/1048_longest_string_chain.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@
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, and each time we have to delete each character O(NC), it would then be O(NC) + 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.
14-
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.
14+
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.
15+
This would mean our run-time goes down tremendously to O(NC) + O(C^C).
16+
This is because we only need to do the O(C^C) check once and not for every N words.
1517

1618
```
1719
class Solution:

0 commit comments

Comments
 (0)