![](https://img-blog.csdnimg.cn/20201014180756928.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
指针移动
mars2014jia
这个作者很懒,什么都没留下…
展开
-
天题之reverse list
最后那个reverse函数写的比较费劲,主要是pre.next 和last.next必须指向正确位置ref 解释 http://www.cnblogs.com/lichen782/p/leetcode_Reverse_Nodes_in_kGroup.htmlref 代码 http://www.cnblogs.com/springfor/p/3864530.htmlpublic clas转载 2015-03-25 16:28:03 · 214 阅读 · 0 评论 -
Rotate List
做个circle ,看讨论来的关键是怎么找到从哪里切,最后个循环的条件 len - k%lenpublic class Solution { public ListNode rotateRight(ListNode head, int k) { if(head==null || head.next == null ||k==0) return head;原创 2015-03-18 11:20:27 · 187 阅读 · 0 评论 -
Reorder List
1) 怎么写reverse linkedlist 逻辑图 http://www.geeksforgeeks.org/write-a-function-to-reverse-the-nodes-of-a-linked-list/2) 注意first half和second half 都要有null 结尾ref http://www.cnblogs.com/springfor/p/386933转载 2015-03-18 09:02:07 · 280 阅读 · 0 评论 -
Reverse Linked List II
// ref // http://blog.csdn.net/linhuanmars/article/details/24613781难点,多指针操作public class Solution { public ListNode reverseBetween(ListNode head, int m, int n) { ListNode dummy = new L转载 2015-03-13 04:12:16 · 198 阅读 · 0 评论 -
Longest Substring Without Repeating Characters
public class Solution { //ref http://blog.csdn.net/linhuanmars/article/details/19949159 很精妙的解法哟 public int lengthOfLongestSubstring(String s) { if(s==null || s.length()<1转载 2015-03-11 04:12:50 · 198 阅读 · 0 评论 -
Recover Binary Search Tree
重点1 inorder2 怎么用O(1)的space, 必然是用tmp的指针做swapref http://www.cnblogs.com/springfor/p/3891390.htmlpublic class Solution { TreeNode first, pre, second; public void recoverTree(TreeNode root转载 2015-03-21 05:26:26 · 190 阅读 · 0 评论 -
Insert Interval
最后一个元素的处理是关键,要记得移动完成后加上去 public ArrayList insert(ArrayList intervals, Interval newInterval) { // 跟之前那道题一样嘛 不要那么麻烦http://www.cnblogs.com/springfor/p/3872333.html ArrayList res =转载 2015-03-21 06:47:29 · 210 阅读 · 0 评论 -
Remove Duplicates from Sorted List II
注意这里通过比较node而非值,判断了pre 指针和cur 指针的位置,从而穿针引线ref http://blog.csdn.net/linhuanmars/article/details/24389429public class Solution { public ListNode deleteDuplicates(ListNode head) {转载 2015-03-17 04:48:40 · 282 阅读 · 0 评论 -
Merge k Sorted Lists
1) 复习下merge sort的各个部分怎么写2) 注意每个method的返回值ref http://www.cnblogs.com/springfor/p/3869217.htmlpublic class Solution { // ref http://www.cnblogs.com/springfor/p/3869217.html public ListNode转载 2015-03-17 03:43:39 · 220 阅读 · 0 评论 -
Spiral Matrix II
public class Solution { public int[][] generateMatrix(int n) { // 模仿代码https://leetcodenotes.wordpress.com/2013/11/23/leetcode-spiral-matrix-%E6%8A%8A%E4%B8%80%E4%B8%AA2d-matrix%E7%94%A8%E8%9E%BA%E转载 2015-03-20 04:27:13 · 189 阅读 · 0 评论 -
Sort List
这道题目关键是考虑怎么实现O nlogn ,所以要找到中点,迭代,其他和merge sort 2 list 一样参考 http://www.cnblogs.com/springfor/p/3869372.htmlpublic class Solution { // 问题关键要想到找中点,然后迭代产生O(nlogn) public ListNode sortList(转载 2015-03-17 01:45:23 · 179 阅读 · 0 评论 -
First Missing Positive
题目分析要求:转载自 https://leetcodenotes.wordpress.com/2013/07/17/first-missing-positive/要求这么高,还不让用空间换时间,说明不是dp,所以基本只让过一两遍数组,一边过一遍直接in place的改动数组(不让生成新数组啊)既然是大部分不missing,所以可以用index来直接和元素产生关系。试图让转载 2015-03-20 12:50:05 · 323 阅读 · 0 评论 -
Multiply Strings
ref 的code写的很漂亮 http://blog.csdn.net/fightforyourdream/article/details/17370495public class Solution { public String multiply(String num1, String num2) { if(num1==null||num2==null) return转载 2015-03-20 12:34:18 · 190 阅读 · 0 评论 -
Spiral Matrix
// 先看II,然后I就秒改public class Solution { public ArrayList spiralOrder(int[][] matrix) { ArrayList res = new ArrayList(); if(matrix==null || matrix.length==0 || matrix[0].length==0) re原创 2015-03-20 04:38:47 · 178 阅读 · 0 评论 -
难题部分Copy List with Random Pointer
别的都不说,这部分题对我来说,首先就是看不懂题意A linked list is given such that each node contains an additional random pointer which could point to any node in the list or null.Return a deep copy of the list./*转载 2015-03-27 05:48:56 · 231 阅读 · 0 评论 -
天题之滑动窗口 Minimum Window Substring
不要用hashmappublic class Solution { public String minWindow(String S, String T) { // 讲解http://articles.leetcode.com/2010/11/finding-minimum-window-in-s-which.html //代码 http://www.c转载 2015-03-25 08:01:24 · 378 阅读 · 0 评论 -
天题之滑动窗口Substring with Concatenation of All Words
我觉得我没有理解第一层loop的精髓代码部分完全参考 ref public class Solution { public ArrayList findSubstring(String S, String[] L) { //http://www.cnblogs.com/springfor/p/3872516.html ArrayList res =转载 2015-03-25 04:40:15 · 231 阅读 · 0 评论