摘要:
题目链接 因为需要用到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)