11 2022 档案

摘要:今天是第四十九天,用动态规划的思想去解决之前用贪心算法解决的股票买卖问题 121. 买卖股票的最佳时机 class Solution { public int maxProfit(int[] prices) { int n = prices.length; if(n == 1){ return 0; 阅读全文
posted @ 2022-11-30 16:15 小猫Soda 阅读(12) 评论(0) 推荐(0) 编辑
摘要:今天是训练营的第四十八天,开始了动态规划的强盗问题 198. 打家劫舍 class Solution { public int rob(int[] nums) { int n = nums.length; if(n==1){ return nums[0]; } int[] dp = new int[ 阅读全文
posted @ 2022-11-30 03:49 小猫Soda 阅读(15) 评论(0) 推荐(0) 编辑
摘要:今天是第四十六天,动态规划周的最后一天 139. 单词拆分 class Solution { public boolean wordBreak(String s, List<String> wordDict) { int n = s.length(); boolean[] dp = new bool 阅读全文
posted @ 2022-11-27 06:22 小猫Soda 阅读(13) 评论(0) 推荐(0) 编辑
摘要:今天是第四十五天,继续动态规划 70. 爬楼梯 (进阶) class Solution { public int climbStairs(int n) { int[] dp = new int[n+1]; dp[0] = 1; for(int i = 0; i<=n; i++){ for(int j 阅读全文
posted @ 2022-11-26 16:19 小猫Soda 阅读(13) 评论(0) 推荐(0) 编辑
摘要:今天是第四十四天,继续动态规划 518. 零钱兑换 II class Solution { public int change(int amount, int[] coins) { int n = coins.length; int[] dp = new int[amount+1]; dp[0] = 阅读全文
posted @ 2022-11-25 15:32 小猫Soda 阅读(13) 评论(0) 推荐(0) 编辑
摘要:今天是第四十三天,还是背包问题 1049. 最后一块石头的重量 II class Solution { public int lastStoneWeightII(int[] stones) { int n = stones.length; int sum = 0; for (int i : ston 阅读全文
posted @ 2022-11-24 13:29 小猫Soda 阅读(12) 评论(0) 推荐(0) 编辑
摘要:今天是第四十二天,是动态规划中的背包问题 416. 分割等和子集 class Solution { public boolean canPartition(int[] nums) { int sum = 0; int n = nums.length; int[] dp = new int[10001 阅读全文
posted @ 2022-11-23 11:58 小猫Soda 阅读(14) 评论(0) 推荐(0) 编辑
摘要:今天是四十一天,从今天起难度大概就要上来了 343.整数拆分 class Solution { public int integerBreak(int n) { int[] dp = new int[n+1]; dp[2] = 1; for(int i = 3; i<=n; i++){ for(in 阅读全文
posted @ 2022-11-21 02:27 小猫Soda 阅读(14) 评论(0) 推荐(0) 编辑
摘要:今天是第三十九天,只有两道动态规划的题 62.不同路径 class Solution { public int uniquePaths(int m, int n) { int[][] path = new int[m][n]; for(int i = 0; i<m; i++){ path[i][0] 阅读全文
posted @ 2022-11-20 01:48 小猫Soda 阅读(15) 评论(0) 推荐(0) 编辑
摘要:今天是第三十八天,最难的动态规划要开始了 509. 斐波那契数 class Solution { public int fib(int n) { if(n < 2){ return n; }int[] fibNum = new int[n+1]; fibNum[0] = 0; fibNum[1] = 阅读全文
posted @ 2022-11-19 12:10 小猫Soda 阅读(16) 评论(0) 推荐(0) 编辑
摘要:今天是第三十七天,贪心算法的最后一天 738.单调递增的数字 class Solution { public int monotoneIncreasingDigits(int n) { String num = Integer.toString(n); char[] nums = num.toCha 阅读全文
posted @ 2022-11-18 06:43 小猫Soda 阅读(15) 评论(0) 推荐(0) 编辑
摘要:今天继续是贪心算法 435. 无重叠区间 class Solution { public int eraseOverlapIntervals(int[][] intervals) { int n = intervals.length; Arrays.sort(intervals, (a, b) -> 阅读全文
posted @ 2022-11-17 15:24 小猫Soda 阅读(17) 评论(0) 推荐(0) 编辑
摘要:第三十五天,继续贪心 860.柠檬水找零 class Solution { public boolean lemonadeChange(int[] bills) { int n = bills.length; if(bills[0] > 5){ return false; } int five = 阅读全文
posted @ 2022-11-16 13:34 小猫Soda 阅读(15) 评论(0) 推荐(0) 编辑
摘要:今天继续贪心算法,重点是学习贪心算法的思维 1005.K次取反后最大化的数组和 class Solution { public int largestSumAfterKNegations(int[] nums, int k) { int n = nums.length; Arrays.sort(nu 阅读全文
posted @ 2022-11-15 14:20 小猫Soda 阅读(21) 评论(0) 推荐(0) 编辑
摘要:本来这是第三十一天的内容,但是三十一天的时候写成第三十二天的了,因此今天写第三十一天的内容 455.分发饼干 class Solution { public int findContentChildren(int[] g, int[] s) { Arrays.sort(g); Arrays.sort 阅读全文
posted @ 2022-11-14 16:34 小猫Soda 阅读(13) 评论(0) 推荐(0) 编辑
摘要:贪心算法的核心思想是在每一步决策中都找到局部最优解 122. 买卖股票的最佳时机 class Solution { public int maxProfit(int[] prices) { int n = prices.length; int profit = 0; int price = pric 阅读全文
posted @ 2022-11-12 15:27 小猫Soda 阅读(14) 评论(0) 推荐(0) 编辑
摘要:今天是第二十八天,依旧是回溯 491. 递增子序列 class Solution { private List<Integer> path = new ArrayList<>(); private List<List<Integer>> res = new ArrayList<>(); public 阅读全文
posted @ 2022-11-10 15:27 小猫Soda 阅读(17) 评论(0) 推荐(0) 编辑
摘要:今天是第二十八天,前面几天的回溯算法不太熟,今天继续巩固 ● 93.复原IP地址 class Solution { List<String> ret = new ArrayList<>(); public List<String> restoreIpAddresses(String s) { Lin 阅读全文
posted @ 2022-11-09 15:21 小猫Soda 阅读(13) 评论(0) 推荐(0) 编辑
摘要:第二十七天,继续回溯算法 39. 组合总和 class Solution { List<Integer> list = new ArrayList<>(); List<List<Integer>> ans = new ArrayList<>(); int target; int len; publi 阅读全文
posted @ 2022-11-08 15:17 小猫Soda 阅读(14) 评论(0) 推荐(0) 编辑
摘要:今天是第二十五天,回溯算法 216. 组合总和III class Solution { List<List<Integer>> res = new ArrayList<>(); List<Integer> paths = new ArrayList<>(); int sum = 0; public 阅读全文
posted @ 2022-11-06 12:20 小猫Soda 阅读(21) 评论(0) 推荐(0) 编辑
摘要:今天结束了二叉树的学习, 开始新的一章了 77.组合 class Solution { List<List<Integer>> res = new ArrayList<List<Integer>>(); List<Integer> list = new ArrayList<Integer>(); p 阅读全文
posted @ 2022-11-05 01:37 小猫Soda 阅读(19) 评论(0) 推荐(0) 编辑
摘要:今天终于是 二叉树的最后一章了,三道题,加油! 669. 修剪二叉搜索树 class Solution { public TreeNode trimBST(TreeNode root, int low, int high) { if(root == null){ return root; } roo 阅读全文
posted @ 2022-11-03 14:44 小猫Soda 阅读(8) 评论(0) 推荐(0) 编辑
摘要:今天是第22天,依旧还是二叉树 235. 二叉树的最近公共祖先 class Solution { public TreeNode lowestCommonAncestor(TreeNode root, TreeNode p, TreeNode q) { if(root == null){ retur 阅读全文
posted @ 2022-11-02 13:28 小猫Soda 阅读(17) 评论(0) 推荐(0) 编辑
摘要:今天是第二十一天,还是二叉树,做了得有一周的二叉树了 530.二叉搜索树的最小绝对差 class Solution { int res = Integer.MAX_VALUE; TreeNode pre = null; public int getMinimumDifference(TreeNode 阅读全文
posted @ 2022-11-01 13:47 小猫Soda 阅读(15) 评论(0) 推荐(0) 编辑

点击右上角即可分享
微信分享提示