摘要:
61. Rotate List 方法一:做k次rotation。 1.corner case需要考虑 2.当k远远大于的计算量的时候,记得算出链表长度并对长度求余。 class Solution { public ListNode rotateRight(ListNode head, int k) 阅读全文
摘要:
25. Reverse Nodes in k-Group 用栈的形式存储k个节点并反转,一个是用来入栈分段的,一个是用来出栈翻转的 空间复杂度O( N ) class Solution { public ListNode reverseKGroup(ListNode head, int k) { i 阅读全文
摘要:
322. Coin Change class Solution { public int coinChange(int[] coins, int amount) { int[] dp = new int[amount + 1]; Arrays.fill(dp, amount + 1); dp[0] 阅读全文
摘要:
291. Word Pattern II class Solution { public boolean wordPatternMatch(String pattern, String str) { Map<Character, String> map = new HashMap<>(); retu 阅读全文
摘要:
236. Lowest Common Ancestor of a Binary Tree - 若p和q分别位于左右子树中,那么对左右子结点调用递归函数,会分别返回p和q结点的位置,而当前结点正好就是p和q的最小共同父结点,直接返回当前结点即可,这就是题目中的例子1的情况。 - 若p和q同时位于左子树 阅读全文
摘要:
29. Divide Two Integers class Solution { public int divide(int dividend, int divisor) { if(dividend == Integer.MIN_VALUE && divisor == -1) return Inte 阅读全文
摘要:
161. One Edit Distance 1. 两个字符串的长度之差大于1,直接返回False。 2. 两个字符串的长度之差等于1,长的那个字符串去掉一个字符,剩下的应该和短的字符串相同。 3. 两个字符串的长度之差等于0,两个字符串对应位置的字符只能有一处不同。 class Solution 阅读全文
摘要:
309. Best Time to Buy and Sell Stock with Cooldown class Solution { public int maxProfit(int[] prices) { if(prices == null || prices.length <= 1) retu 阅读全文
摘要:
55. Jump Game 希望知道能否到达末尾,也就是说我们只对最远能到达的位置感兴趣,所以维护一个变量 reach,表示最远能到达的位置,初始化为0。遍历数组中每一个数字,如果当前坐标大于 reach 或者 reach 已经抵达最后一个位置则跳出循环,否则就更新 reach 的值为其和 i + 阅读全文
摘要:
359. Logger Rate Limiter 用map搭建。 class Logger { HashMap<String, Integer> map; /** Initialize your data structure here. */ public Logger() { map = new 阅读全文