Day34-DynamicProgramming02
62. Unique Paths
Node:
Time Complexity && Space Complexity
- Time Complexity: O(m*n)
- Space Complexity: O(m*n)
1 | var uniquePaths = function(m, n) { |
63. Unique Paths II
Node:
Time Complexity && Space Complexity
- Time Complexity: O(m*n)
- Space Complexity: O(m*n)
1 | /** |
343. Integer Break
Node:
- Example of 10
- 5*5
- 4*6
- 3*7
- 2*8
- 1*9
- The max product of 9
- 5*4
- 6*3
- 7*2
- 8*1
Time Complexity && Space Complexity
- Time Complexity: O(n^2)
- Space Complexity: O(n)
1 | var integerBreak = function(n) { |
96. Unique Binary Search Trees
Node:
- dp[4] = dp[3] * dp[0] + dp[2] * dp[1] + dp[1] * dp[2] + dp[0] * dp[3]
- except the root node, there are four way of the childs:
- left: 3 nodes, right: 0 node
- left: 2 nodes, right: 1 node
- left: 1 nodes, right: 2 node
- left: 0 nodes, right: 3 node
- dp[3] = dp[2] * dp[0] + dp[1] * dp[1] + dp[0] * dp[2]
- except the root node, there are three way of the childs:
- left: 2 nodes, right: 0 node
- left: 1 nodes, right: 1 node
- left: 0 nodes, right: 2 node
Time Complexity && Space Complexity
- Time Complexity: O(n^2)
- Space Complexity: O(n)
1 | var numTrees = function(n) { |
- Title: Day34-DynamicProgramming02
- Author: Guoyi
- Created at : 2024-12-05 16:39:31
- Updated at : 2024-12-07 03:58:41
- Link: https://guoyiwang.github.io/Algorithm/Day34-DynamicProgramming02/
- License: This work is licensed under CC BY-NC-SA 4.0.
Comments