
Divide and Conque
iteye_17352
这个作者很懒,什么都没留下…
展开
-
Leetcode - Merge k Sorted Lists
Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity.[分析] 有了Merge 2 sorted lists的铺垫做这题就容易了,自己写了递归版的method1, 翻看历史记录,有迭代版的和heap sort版本,觉得method1 & 2写得更顺手...原创 2015-07-08 09:57:02 · 84 阅读 · 0 评论 -
Leetcode - Median of Two Sorted Arrays
There are two sorted arrays nums1 and nums2 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)).[分析] 暴力法是简单的,合并后返回中位数。优化的...原创 2015-07-12 11:02:04 · 72 阅读 · 0 评论 -
Leetcode - Different Ways to Add Parentheses
Given a string of numbers and operators, return all possible results from computing all the different possible ways to group numbers and operators. The valid operators are +, - and *.Example 2Inpu...原创 2015-07-29 20:21:33 · 92 阅读 · 0 评论 -
Leetcode - Sort List
Sort a linked list in O(n log n) time using constant space complexity.[分析] 将链表二分,递归排序子链表,然后merge 已排序的两子链表。[code="java"]public class Solution { public ListNode sortList(ListNode head) {...原创 2015-08-15 17:41:46 · 87 阅读 · 0 评论 -
Leetcode - The Skyline Problem
[分析]思路1参考[url]https://leetcode.com/discuss/44537/my-java-ac-code-with-priorityqueues[/url]记录下目前的理解:目标是求出所有拐点。所谓拐点是指让当前x坐标高度发生变化的点,当前x坐标的高度是x处所有楼房的最大高度。所有楼房的左右两顶点加入到考察集合,排序该集合,排序后使用最大堆来保存当前的楼高状态,遍历...原创 2015-09-04 19:09:42 · 135 阅读 · 0 评论 -
Leetcode - Unique Binary Search Trees II
Given n, generate all structurally unique BST's (binary search trees) that store values 1...n.For example,Given n = 3, your program should return all 5 unique BST's shown below. 1 3 3...原创 2015-04-20 09:30:17 · 79 阅读 · 0 评论 -
Leetcode - Best Time to Buy and Sell Stock III
Say you have an array for which the ith element is the price of a given stock on day i.Design an algorithm to find the maximum profit. You may complete at most two transactions.Note:You may not ...原创 2015-04-23 09:04:36 · 86 阅读 · 0 评论 -
Leetcode - Kth Largest Element in an Array
Find the kth largest element in an unsorted array. Note that it is the kth largest element in the sorted order, not the kth distinct element.For example, Given [3,2,1,5,6,4] and k = 2, return 5....原创 2015-05-23 21:25:28 · 101 阅读 · 0 评论