摘要: 题目链接 class Solution { public int maxProfit(int[] prices) { if(prices.length <= 1) return 0; int low = prices[0],res = 0; for(int i=1;i<prices.length;i 阅读全文
posted @ 2022-02-07 20:41 蹇爱黄 阅读(27) 评论(0) 推荐(0)
摘要: 题目链接 递归 class Solution { public int maxDepth(TreeNode root) { if(root==null) return 0; //左子树递归 int left = maxDepth(root.left); //右子树递归 int right = max 阅读全文
posted @ 2022-02-07 20:24 蹇爱黄 阅读(28) 评论(0) 推荐(0)
摘要: 题目链接 我直接跪 我直接背 阅读全文
posted @ 2022-02-07 19:57 蹇爱黄 阅读(25) 评论(0) 推荐(0)
摘要: 题目链接 思路 标签:从后向前数组遍历 因为 nums1 的空间都集中在后面,所以从后向前处理排序的数据会更好,节省空间,一边遍历一边将值填充进去 设置指针 r1 和 r2 分别指向 nums1 和 nums2 的有数字尾部,从尾部值开始比较遍历,同时设置指针 len 指向 nums1 的最末尾,每 阅读全文
posted @ 2022-02-07 19:24 蹇爱黄 阅读(38) 评论(0) 推荐(0)
摘要: 题目链接 看来还得读写几个题才会有感觉 力扣的大佬是真的多 class Solution { List<List<Integer>> res; List<Integer> path; public List<List<Integer>> subsets(int[] nums) { res = new 阅读全文
posted @ 2022-02-07 17:06 蹇爱黄 阅读(34) 评论(0) 推荐(0)
摘要: 题目链接 动态规划找到递推公式,确定好开始两项的值 class Solution { public int climbStairs(int n) { if(n<=2) return n; int[] dp = new int[n+1]; //数组从第二个元素开始,第一个位置dp[0]不用,这样可以跟 阅读全文
posted @ 2022-02-07 16:09 蹇爱黄 阅读(38) 评论(0) 推荐(0)
摘要: 题目链接 递归 class Solution { public int uniquePaths(int m, int n) { return dfs(new HashMap<Pair,Integer>(),0,0,m,n); } private int dfs(Map<Pair,Integer> c 阅读全文
posted @ 2022-02-07 01:55 蹇爱黄 阅读(37) 评论(0) 推荐(0)
摘要: 题目链接 class Solution { public ListNode rotateRight(ListNode head, int k) { if(head == null) return null; int len = 1; ListNode tail = head; while(tail. 阅读全文
posted @ 2022-02-07 01:25 蹇爱黄 阅读(29) 评论(0) 推荐(0)