摘要: 感觉贼难啊 在Java里边比较简单 class LRUCache extends LinkedHashMap<Integer, Integer>{ private int capacity; public LRUCache(int capacity){ super(capacity,0.75F,tr 阅读全文
posted @ 2022-02-08 23:59 蹇爱黄 阅读(48) 评论(0) 推荐(0)
摘要: 题目链接 判断环的入口,需要先判断有没有环,在寻找环的入口,找入口时需要重新定义两个”指针“,一个指向头节点,一个指向当前fast,让他们前进速度相同,他们想入的点即为入口。 public class Solution { public ListNode detectCycle(ListNode h 阅读全文
posted @ 2022-02-08 17:12 蹇爱黄 阅读(49) 评论(0) 推荐(0)
摘要: 题目链接 因为需要用到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 蹇爱黄 阅读(35) 评论(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 蹇爱黄 阅读(29) 评论(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 蹇爱黄 阅读(42) 评论(0) 推荐(0)
摘要: 题目链接 动态规划 考虑到「不能同时参与多笔交易」,因此每天交易结束后只可能存在手里有一支股票或者没有股票的状态。 定义状态 dp[i][0] 表示第 i 天交易完后手里没有股票的最大利润,dp[i][1] 表示第 i 天交易完后手里持有一支股票的最大利润(i 从 0 开始)。 考虑 dp[i][0 阅读全文
posted @ 2022-02-08 15:36 蹇爱黄 阅读(30) 评论(0) 推荐(0)