1. 最长递增子序列 LIS (中等)
地址: https://leetcode-cn.com/problems/longest-increasing-subsequence/
2021/12/26
做题反思:
class Solution {
public int lengthOfLIS(int[] nums) {
int n = nums.length;
int[] dp = new int[n];
Arrays.fill(dp, 1);
for (int i = 1; i < n; i++) {
for (int j = 0; j < i; j++) {
if (nums[i] > nums[j]) {
dp[i] = Math.max(dp[i], dp[j] + 1);
}
}
}
int res = 0;
for (int i = 0; i < n; i++) {
res = Math.max(res, dp[i]);
}
return res;
}
}
2. 俄罗斯套娃信封问题(困难)
(华为2021.8、新浪、微软)
地址: https://leetcode-cn.com/problems/russian-doll-envelopes/
2021/12/
做题反思:
3. 最大子数组和 (简单)
地址: https://leetcode-cn.com/problems/maximum-subarray/
2021/12/26
做题反思:
class Solution {
public int maxSubArray(int[] nums) {
int n = nums.length;
int[] dp = new int[n];
dp[0] = nums[0];
for (int i = 1; i < n; i++) {
dp[i] = Math.max(nums[i], dp[i - 1] + nums[i]);
}
int res = Integer.MIN_VALUE;
for (int i = 0; i < n; i++) {
res = Math.max(res, dp[i]);
}
return res;
}
}