![](https://img-blog.csdnimg.cn/20201014180756928.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
LeetCode
CAFEBABE丶
颤抖吧丶发际线
展开
-
LeetCode_median-of-two-sorted-arrays
题目描述:There are two sorted arrays A and B of size m and n respectively. Find the median of the two sorted arrays. The overall run time complexity should be O(log (m+n)).思路:要找出两个排序数组的中位数,如果对两个数组进行合并再处...原创 2018-07-24 09:54:15 · 192 阅读 · 0 评论 -
LeetCode_对链表进行排序
题目描述: Sort a linked list in O(n log n) time using constant space complexity. 思路1:要实现O(nlogn)的话可以考虑使用归并排序,这里有个问题就是寻找中间节点。寻找中间节点的时候,用快慢指针的时候,有两种写法,一种会出现栈溢出,要特别注意。注意事项在代理中...原创 2018-07-20 11:06:06 · 2109 阅读 · 0 评论 -
LeetCode_reorder-list
题目描述: Given a singly linked list L: L 0→L 1→…→L n-1→L n,reorder it to: L 0→L n →L 1→L n-1→L2→L n-2→…You must do this in-place without altering the nodes' values.For example, Given{1,2,3,4}, re...原创 2018-07-20 14:30:57 · 123 阅读 · 0 评论 -
LeetCode_linked-cycle-ii
题目描述: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?思路(用剑指Offer中HashMap的算法当然也是可以的,不过这题要求不用额外空...原创 2018-07-20 15:03:09 · 107 阅读 · 0 评论 -
LeetCode_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.思路1:用HashMap把原来节点和CoPY节点...原创 2018-07-20 16:27:47 · 173 阅读 · 0 评论 -
LeetCode_convert-sorted-list-to-binary-search-tree
题目描述:Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST.思路:二叉查找树的中序遍历就是排序的数,那么我们可以通过中序遍历来构建这个树直接看代码,下面一般是改进的 ,这里题目要求的是,当节点是偶数的时候,以n/2+1个...原创 2018-07-20 17:33:54 · 130 阅读 · 0 评论 -
LeetCode_rotate-list
题目描述:Given a list, rotate the list to the right by kplaces, where k is non-negative.For example:Given1->2->3->4->5->NULLand k =2,return4->5->1->2->3->NULL.这个意思有点表...原创 2018-07-21 20:34:05 · 141 阅读 · 0 评论 -
LeetCode_merge-k-sorted-lists
题目描述: Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity.思路1:用堆排序,每次都是从k条链表里面取出这k个节点中的最小值,然后拼接起来,取这个k个节点就可以使用堆来操作了;思路2:用分治的思想,和归并排序一样,每次合...原创 2018-07-21 22:08:41 · 124 阅读 · 0 评论 -
LeetCode_maximal-rectangle
题目描述: Given a 2D binary matrix filled with 0's and 1's, find the largest rectangle containing all ones and return its area.主要是注意 公式中宽度的求取: import java.util.*;//本题是求直方图中最大矩形面积的变形pu...原创 2018-08-01 17:44:56 · 137 阅读 · 0 评论