https://leetcode.com/problems/maximum-subarray/Find the contiguous subarray within an array (containing at least one number) which has the largest sum...
分类:
其他好文 时间:
2015-08-02 11:43:32
阅读次数:
95
这题是典型的堆排序算法,只是比一般的堆算法多了删除的操作,有两件事需要做:1 用一个hash表存储从输入数组索引到堆数组(用于实现堆的那个数组)所以的映射,以便在需要删除一个元素的时候能迅速定位到堆数组中的位置2用一个set保存已经被删除的元素索引(这里指的是输入数组索引),这一点可选;还有一种做法...
很有趣的一道题,题解戳这。 1 #include 2 #include 3 #include 4 #include 5 using namespace std; 6 7 const int maxn = 200000 + 10; 8 const int maxm = 1000000 + 1...
分类:
其他好文 时间:
2015-08-02 10:03:44
阅读次数:
123
Given a binary tree, find its maximum depth.
The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.
思路:很基础的一个题,DFS即可。代码如下:
/**
* Defin...
分类:
其他好文 时间:
2015-08-01 22:08:25
阅读次数:
140
传送门十分重要的基础DP问题,是学习用各种方式优化DP的一个很好的例子。设DP[i]表示以a[i]结尾的LIS的长度,则状态转移方程为DP[1]=1DP[i] = max{DP[j], j1暴力求解复杂度为O(N^2)。优化1考虑函数f(L):长度为 L 的 Increasing Sequence ...
分类:
其他好文 时间:
2015-08-01 20:28:08
阅读次数:
90
Givennpoints on a 2D plane, find the maximum number of points that lie on the same straight line./** * Definition for a point. * class Point { * i...
分类:
其他好文 时间:
2015-08-01 20:26:30
阅读次数:
118
<!DOCTYPE?html>
<html?lang="en">
<head>
????<meta?charset="UTF-8">
????<title>转盘</title>
????<meta?name="viewport"?content="width=device-width,?maximum-scale=1.0,?user-scalab...
分类:
Web程序 时间:
2015-08-01 17:30:41
阅读次数:
170
一、枚举所有宽度为举着宽度的子矩阵,从中找出是否具有相应长度的正方形,复杂度为O(n^3);二、[1]中使用动态规划,decrease the complexity to O(n^2)dp[i][j] mean the maximum square which has right-down corn...
分类:
其他好文 时间:
2015-08-01 15:40:02
阅读次数:
108
//一个无向图,两点之间的流量为c,两点花的时间为t
//问从起点到终点n之间时间小于等于T且只走一条路径能够运输的最大流量为多少
//二分流量,小于这个流量的路径不走,求其时间是否小于等于T得到答案
#include
#include
#include
#include
using namespace std ;
const in...
分类:
其他好文 时间:
2015-08-01 14:18:53
阅读次数:
117
该题的思路是使用辅助数组来保存从前向后和从后向前到当前位置的最大最小值,这样就可以通过每一个位置处的最大最小值来计算该位置的结果,最后在所有结果中选出最大的值即可。
int maxDiffSubArrays(vector nums) {
// write your code here
int size = nums.size();
/...
分类:
其他好文 时间:
2015-07-31 18:22:21
阅读次数:
110