随笔分类 -  LeetCode (Java)

使用Java刷题LeetCode
摘要:零钱兑换。 思路:动态规划。 利用规律: \(dp[i] = min\{ dp[i - coins[j]] \} + 1, \quad i: 0 \rightarrow coins.length\) class Solution { public int coinChange(int[] coins 阅读全文
posted @ 2020-12-21 15:18 模糊计算士 阅读(63) 评论(0) 推荐(0) 编辑
摘要:使用最小花费爬楼梯 代码: class Solution { public int minCostClimbingStairs(int[] cost) { int[] dp = new int[cost.length + 1]; dp[0] = 0; dp[1] = cost[0]; for (in 阅读全文
posted @ 2020-12-21 13:21 模糊计算士 阅读(72) 评论(0) 推荐(0) 编辑
摘要:题目链接:https://leetcode-cn.com/problems/remove-duplicate-letters 思路:这题应该考虑挑选,而不是删除。 代码: public String removeDuplicateLetters(String s) { int[] map = new 阅读全文
posted @ 2020-12-20 17:30 模糊计算士 阅读(86) 评论(0) 推荐(0) 编辑
摘要:问题描述: 问题地址:https://leetcode-cn.com/problems/container-with-most-water/ 代码: public int maxArea(int[] height) { if (height.length <= 1) { return -1; } i 阅读全文
posted @ 2020-09-30 19:52 模糊计算士 阅读(160) 评论(0) 推荐(0) 编辑
摘要:题目地址:https://leetcode-cn.com/problems/hanota-lcci/submissions/ 题目描述: 分析:假设我们在A柱子上有8个圆盘需要移动到C柱子上面,那么利用递归思想,我们只需要先将上面的7个圆盘移动到B柱子上,然后将最底下的圆盘移动到C柱子上,再将B柱子 阅读全文
posted @ 2020-09-09 11:36 模糊计算士 阅读(131) 评论(0) 推荐(0) 编辑
摘要:我记得我看浙大数据结构的时候,何老师有提到过用类似的堆栈可以解决编译器的有关问题。而且当时还有一道运算类的习题,偏偏我做题时没有想到。还是要多刷题,长见识。 1 package fanlu.leetcode; 2 3 import java.util.Stack; 4 5 public class 阅读全文
posted @ 2020-03-29 22:08 模糊计算士 阅读(202) 评论(0) 推荐(0) 编辑