1048. Longest String Chain

https://leetcode.com/problems/longest-string-chain/discuss/1543825/Java-DP-with-HashMap-clear-explanation

DP with HashMap

1. from shortest words, words[] sort by length

2. dp with hashmap

3. for each word

why count = Math.max(count, map.get(findStr)+1); needs do max?

time: O(nlogn + n*w), n is words[i].length (1~16) , w is word length(1~1000)

space: O(n)

Last updated

Was this helpful?