上一页 1 ··· 3 4 5 6 7 8 9 10 11 ··· 15 下一页
摘要: class Solution { public String convertToTitle(int n) { if(n <= 0) return ""; StringBuilder sb = new StringBuilder(); while(n > 0) { n--; sb.append((ch 阅读全文
posted @ 2020-08-06 16:22 Sexyomaru 阅读(78) 评论(0) 推荐(0) 编辑
摘要: 方法一:枚举前后缀,使用HashMap class Solution { public List<List<Integer>> palindromePairs(String[] words) { List<List<Integer>> res = new ArrayList<>(); int n = 阅读全文
posted @ 2020-08-06 15:34 Sexyomaru 阅读(190) 评论(0) 推荐(0) 编辑
摘要: class Solution { public int countGoodTriplets(int[] arr, int a, int b, int c) { int n = arr.length, res = 0; for(int i = 0; i < n - 2; i++) { for(int 阅读全文
posted @ 2020-08-04 15:52 Sexyomaru 阅读(111) 评论(0) 推荐(0) 编辑
摘要: 方法一:滑动窗口 class Solution { public int[] smallestRange(List<List<Integer>> nums) { int size = nums.size(); Map<Integer,List<Integer>> map = new HashMap< 阅读全文
posted @ 2020-08-04 10:30 Sexyomaru 阅读(166) 评论(0) 推荐(0) 编辑
摘要: 分析: 这是道二维费用的背包问题,可以像01背包一样优化掉第一维的决策,选或不选这个袋子,然后需要像01背包一样倒序循环体积,和01背包的优化一样。 其次,这道题的难点是可以买多,只要买够就行,我们只需要对负数的体积取0就行,表示我们即使当前需要的饮料小于袋子中的饮料数量,我们依然可以购买,只要从0 阅读全文
posted @ 2020-07-31 15:07 Sexyomaru 阅读(132) 评论(0) 推荐(0) 编辑
摘要: 分析:贪心加回溯 import java.util.*; public class Solution { /** * 返回最后要输出的答案 * @param n int整型 表示牛牛的数字 * @param m int整型 表示牛妹的数字 * @return int整型 */ public int 阅读全文
posted @ 2020-07-31 15:06 Sexyomaru 阅读(161) 评论(0) 推荐(0) 编辑
摘要: 分析: 首先我们要思考如果让这个NP完全题目复杂度降低,那么可以优先考虑到使用位运算,状态压缩等解决思路。 然后接着思考,我们可以发现,我们所需要的不是整个方案,而只是方案最优解,所以我们只需要记录当前这个方案的最优解即可,那么我们考虑的状态,不久只有,在当前方案i中,目前抵达的点是j。 现在既然装 阅读全文
posted @ 2020-07-31 14:17 Sexyomaru 阅读(166) 评论(0) 推荐(0) 编辑
摘要: 分析: 1. 所谓的状态压缩DP,就是用二进制数保存状态。为什么不直接用数组记录呢?因为用一个二进制数记录方便作位运算。 2. 本题等价于找到所有横放 1 X 2 小方格的方案数,因为所有横放确定了,那么竖放方案是唯一的。 3. 用f[i][j]记录第i-1列已经充满且第i列第j个状态。j状态位等于 阅读全文
posted @ 2020-07-31 11:05 Sexyomaru 阅读(196) 评论(0) 推荐(0) 编辑
摘要: class Solution { public int maxProduct(int[] nums) { int n = nums.length; int preMin = nums[0]; // i 之前最小值 int preMax = nums[0]; // i 之前最大值 int res = 阅读全文
posted @ 2020-07-30 16:04 Sexyomaru 阅读(48) 评论(0) 推荐(0) 编辑
摘要: class Solution { public int maximumSum(int[] arr) { int n = arr.length; int[][] dp = new int[n][2]; // dp[i][0]: 以i结尾未删 dp[i][1]: 以i结尾未删过 dp[0][0] = a 阅读全文
posted @ 2020-07-30 10:58 Sexyomaru 阅读(137) 评论(0) 推荐(0) 编辑
上一页 1 ··· 3 4 5 6 7 8 9 10 11 ··· 15 下一页