摘要:
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 阅读全文
摘要:
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 阅读全文
摘要:
309. Best Time to Buy and Sell Stock with Cooldown class Solution { public int maxProfit(int[] prices) { if(prices == null || prices.length <= 1) retu 阅读全文