53. Maximum Subarray
dp[i] means if the the maximum subarray that contains the ith element.
1 | def maximum_subarray(x): |
1 | def maximum_subarray(x): |
6
300. Longest Increasing Subsequence
这里dp[i]的含义是x[i]在subset中,且是subset中最后一个元素的情况下,最大长度是多少。
1 | def longest_increasing_subsequence(x): |
4
139.Word Break
1 | class Solution(object): |
198. House Robber
1 | def house_robber(x): |
4
303. Range Sum Query - Immutable
1 | class NumArray(object): |
368. Largest Divisible Subset
1 | class Solution(object): |
338. Counting Bits
需要熟悉Bit运算和概念,要能发现countbit(n) = countbit(n/2) + n % 2这么一个方程,就是说一个数乘2意味着bit位左移一位
1 | class Solution(object): |
264. Ugly Number II
1 | def nthUglyNumber(n): |
[1, 2]
[1, 2, 3]
[1, 2, 3, 4]
[1, 2, 3, 4, 5]
[1, 2, 3, 4, 5, 6]
[1, 2, 3, 4, 5, 6, 8]
[1, 2, 3, 4, 5, 6, 8, 9]
[1, 2, 3, 4, 5, 6, 8, 9, 10]
[1, 2, 3, 4, 5, 6, 8, 9, 10, 12]
12
673. Number of Longest Increasing Subsequence
1 | def dp(x): |
[1]
[1]
[1]
[1, 1, 1, 1]
[1, 1, 1, 1]
4
[1, 2]
[1, 2, 3]
[1, 2, 3]
[1, 2, 3, 4, 4]
[1, 2, 3, 4]
[1, 2, 3, 4, 4, 5, 5]
[1, 2]
[1, 1, 1, 1, 2, 1, 3, 1]
[1, 2, 3, 3, 4, 4, 5, 2]
3
1 | a=[1,2,1] |
2