上一页 1 ··· 54 55 56 57 58 59 60 61 62 ··· 72 下一页
摘要: Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST.从给定的有序链表生成平衡二叉树。解题思路:最容易想到的就是利用数组生成二叉树的方法 阅读全文
posted @ 2017-10-19 23:00 乐乐章 阅读(124) 评论(0) 推荐(0) 编辑
摘要: 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 阅读全文
posted @ 2017-10-18 22:32 乐乐章 阅读(132) 评论(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-10-17 10:49 乐乐章 阅读(127) 评论(0) 推荐(0) 编辑
摘要: Given a linked list, return the node where the cycle begins. If there is no cycle, return null. Note: Do not modify the linked list. Follow up:Can you 阅读全文
posted @ 2017-10-16 22:08 乐乐章 阅读(141) 评论(0) 推荐(0) 编辑
摘要: Sort a linked list using insertion sort. 这道题其实主要考察链表的基本操作,用到的小技巧也就是在Swap Nodes in Pairs中提到的用一个辅助指针来做表头避免处理改变head的时候的边界情况。 helper先不和head相连,也是个边界 class 阅读全文
posted @ 2017-10-15 10:54 乐乐章 阅读(138) 评论(0) 推荐(0) 编辑
摘要: 148. Sort List Sort a linked list in O(n log n) time using constant space complexity. 利用mergesort merge 操作只能合并2个有序的子序列 所以利用递归对每个子序列进行排序,排序后merge。 # De 阅读全文
posted @ 2017-10-09 20:51 乐乐章 阅读(147) 评论(0) 推荐(0) 编辑
摘要: 61. Rotate List 61. Rotate List 61. Rotate List 61. Rotate List Given a list, rotate the list to the right by k places, where k is non-negative. For e 阅读全文
posted @ 2017-10-02 22:33 乐乐章 阅读(131) 评论(0) 推荐(0) 编辑
摘要: 21. Merge Two Sorted Lists 21. Merge Two Sorted Lists 21. Merge Two Sorted Lists 21. Merge Two Sorted Lists Merge two sorted linked lists and return i 阅读全文
posted @ 2017-09-25 20:38 乐乐章 阅读(120) 评论(0) 推荐(0) 编辑
摘要: Given a singly linked list, determine if it is a palindrome. Follow up:Could you do it in O(n) time and O(1) space? 思路: 1、 利用快慢指针找到链表中点 2、从中点开始反转链表,判断 阅读全文
posted @ 2017-09-23 22:46 乐乐章 阅读(268) 评论(0) 推荐(0) 编辑
摘要: 141. Linked List Cycle Given a linked list, determine if it has a cycle in it. Follow up:Can you solve it without using extra space? 利用快慢指针,如果相遇则证明有环 阅读全文
posted @ 2017-09-21 16:57 乐乐章 阅读(132) 评论(0) 推荐(0) 编辑
上一页 1 ··· 54 55 56 57 58 59 60 61 62 ··· 72 下一页