Memoization
Decode Ways
brute force DFS solution: O(2^N) Time
improved: memo = DFS + hashMap
fetch from memo map
check index == s.length()
check s.charAt(index) != '0'
check s.substring(index, index + 1)
check s.substring(index, index + 2)
make sure it's not start with '0'
面试时候推荐dfs->memo的思路
Time: O(N), Space: O(N)
除非面试官要求optimal space complexity-> dp with rolling array
Last updated
Was this helpful?