摘要: Given a linked list, return the node where the cycle begins. If there is no cycle, returnnull. Follow up:Can you solve it without using extra space? 快 阅读全文
posted @ 2017-06-07 23:09 鸭子船长 阅读(368) 评论(0) 推荐(0)
摘要: Given a linked list, determine if it has a cycle in it. Follow up:Can you solve it without using extra space? 若在while开始时判断fast==slow,会出现误判,即第一次循环时fast 阅读全文
posted @ 2017-06-07 23:02 鸭子船长 阅读(203) 评论(0) 推荐(0)
摘要: Given a singly linked list L: L0→L1→…→Ln-1→Ln,reorder it to: L0→Ln→L1→Ln-1→L2→Ln-2→… You must do this in-place without altering the nodes' values. For 阅读全文
posted @ 2017-06-07 22:53 鸭子船长 阅读(161) 评论(0) 推荐(0)
摘要: 上面分析了 根据这张图 推倒出 数学公式。 刚接触 不能一下弄明白。下面结合上面文章的分析。仔细推倒一下 , 一般设置 快指针 速度是 慢指针的2倍。及 快指针每次遍历两个指针, 慢指针每次遍历1个指针。 假设上图 快慢指针 在E点相遇,那 相遇点离循环节点D 之间距离是X. 头结点A 离循环节点D 阅读全文
posted @ 2017-06-07 17:35 鸭子船长 阅读(598) 评论(0) 推荐(0)
摘要: Given a binary tree, return the preorder traversal of its nodes' values. For example:Given binary tree{1,#,2,3}, return[1,2,3]. Note: Recursive soluti 阅读全文
posted @ 2017-06-07 17:03 鸭子船长 阅读(217) 评论(0) 推荐(0)
摘要: Given a binary tree, return the postorder traversal of its nodes' values. For example:Given binary tree{1,#,2,3}, return[3,2,1]. Note: Recursive solut 阅读全文
posted @ 2017-06-07 16:52 鸭子船长 阅读(273) 评论(0) 推荐(0)
摘要: Sort a linked list using insertion sort. PS:需要考虑left为head且只有一个数时,此时left->==NULL,若right<left则应更新left。 比较p->next->val与right->val以此来避免需要记录preNode 阅读全文
posted @ 2017-06-07 16:32 鸭子船长 阅读(267) 评论(0) 推荐(0)
摘要: Sort a linked list in O(n log n) time using constant space complexity. 链表,快慢指针找中点,归并排序。 注意判断条件fast->next!=NULL&&fast->next->next!=NULL,若为fast!=NULL&&f 阅读全文
posted @ 2017-06-07 11:29 鸭子船长 阅读(186) 评论(0) 推荐(0)