Given a 2D binary matrix filled with 0's and 1's, find the largest square containing all 1's and return its area.
For example, given the following matrix:
1 0 1 0 0
1 0 1 1 1
1 1 1 1 1
1 0 0 1 0
...
分类:
其他好文 时间:
2015-07-02 10:07:01
阅读次数:
115
题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=1506题目大意: 给出一个数列An,问以Ai为最小值的区间内有多少个元素?解题思路: 手动模拟一个栈。栈内元素为一个单调不递减序列。当新元素Ai需要进栈,如果栈顶元素大于Ai,弹出栈顶元素,直到栈...
分类:
其他好文 时间:
2015-07-01 11:50:27
阅读次数:
111
??
给出一个柱形统计图中,求其中的最大矩形面积
做完这道题,搜了一下题解大部分基本都是单调栈......然而做之前并不知道这是什么,其实用递推也可以做这道题,理解起来比较容易。
用两个数组l,r记录当前坐标可以向左和向右延伸的最远位置的坐标,然后就是递推了。
初始时将l[i],r[i]的值置为i,即自己的坐标。这里拿l[i]举例:
从左向右扫描统计图,计算当前位置的l[i]时,如果...
分类:
其他好文 时间:
2015-06-30 22:04:13
阅读次数:
193
1. 问题描述 找出数组中第k大的数,注意:数组为无序数组。
2. 方法与思路 是一道经典算法题。解法也有好几种,一种是先进行排序,然后取出第k大的数;由于排序算法最快效率为O(nlogn)O(nlogn),所以整体效率为O(nlogn)O(nlogn)。二是使用优先队列,SLT中有优先队列的用法,内部是以堆的方式实现。时间效率也比较高,O(nlogn)O(nlogn)。
class...
分类:
其他好文 时间:
2015-06-29 10:19:30
阅读次数:
97
Given a list of non negative integers, arrange them such that they form the largest number.
For example, given [3, 30, 34, 5, 9], the largest formed number is 9534330.
Note: The result may be ve...
分类:
其他好文 时间:
2015-06-28 12:48:49
阅读次数:
112
Description:Given a list of non negative integers, arrange them such that they form the largest number.For example, given [3, 30, 34, 5, 9], the large...
分类:
其他好文 时间:
2015-06-26 06:50:25
阅读次数:
104
Description: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 eleme...
分类:
其他好文 时间:
2015-06-26 00:19:23
阅读次数:
113
Find the contiguous subarray within an array (containing at least one number) which has the largest sum.For example, given the array[?2,1,?3,4,?1,2,1,...
分类:
其他好文 时间:
2015-06-25 10:17:54
阅读次数:
133
Find the contiguous subarray within an array (containing at least one number) which has the largest product.For example, given the array [2,3,-2,4],
the contiguous subarray [2,3] has the largest produ...
分类:
其他好文 时间:
2015-06-23 23:15:40
阅读次数:
144
Maximum Subarray: https://leetcode.com/problems/maximum-subarray/
Find the contiguous subarray within an array (containing at least one number) which has the largest sum.For example, given the array [...
分类:
其他好文 时间:
2015-06-23 13:40:52
阅读次数:
145