上一页 1 ··· 4 5 6 7 8 9 10 11 12 ··· 14 下一页
摘要: 题目链接 因为需要用到fast.next.next所以必须确保fast!=null && fast.next!=null,才能走到fast = fast.next.next; public class Solution { public boolean hasCycle(ListNode head) 阅读全文
posted @ 2022-02-08 17:03 蹇爱黄 阅读(27) 评论(0) 推荐(0)
摘要: 不开辟新的空间,一般暗示用位运算或者异或解题 class Solution { public int singleNumber(int[] nums) { int single = 0; for(int num:nums){ single ^= num; } return single; } } 大 阅读全文
posted @ 2022-02-08 16:40 蹇爱黄 阅读(22) 评论(0) 推荐(0)
摘要: 题目链接 class Solution { private int res = Integer.MIN_VALUE; public int maxPathSum(TreeNode root) { getMax(root); return res; } private int getMax(TreeN 阅读全文
posted @ 2022-02-08 16:26 蹇爱黄 阅读(30) 评论(0) 推荐(0)
摘要: 题目链接 动态规划 考虑到「不能同时参与多笔交易」,因此每天交易结束后只可能存在手里有一支股票或者没有股票的状态。 定义状态 dp[i][0] 表示第 i 天交易完后手里没有股票的最大利润,dp[i][1] 表示第 i 天交易完后手里持有一支股票的最大利润(i 从 0 开始)。 考虑 dp[i][0 阅读全文
posted @ 2022-02-08 15:36 蹇爱黄 阅读(22) 评论(0) 推荐(0)
摘要: 题目链接 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 蹇爱黄 阅读(22) 评论(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 蹇爱黄 阅读(22) 评论(0) 推荐(0)
摘要: 题目链接 我直接跪 我直接背 阅读全文
posted @ 2022-02-07 19:57 蹇爱黄 阅读(23) 评论(0) 推荐(0)
摘要: 题目链接 思路 标签:从后向前数组遍历 因为 nums1 的空间都集中在后面,所以从后向前处理排序的数据会更好,节省空间,一边遍历一边将值填充进去 设置指针 r1 和 r2 分别指向 nums1 和 nums2 的有数字尾部,从尾部值开始比较遍历,同时设置指针 len 指向 nums1 的最末尾,每 阅读全文
posted @ 2022-02-07 19:24 蹇爱黄 阅读(30) 评论(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 蹇爱黄 阅读(28) 评论(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 蹇爱黄 阅读(28) 评论(0) 推荐(0)
上一页 1 ··· 4 5 6 7 8 9 10 11 12 ··· 14 下一页