明白了上一题是求最大的连续子数组之和后,这题就更加简单了,遇到小于0的就不要加。
public class Solution {
public int maxProfit(int[] prices) {
if(prices.length < 2)
return 0;
int n = prices.length;
...
分类:
其他好文 时间:
2014-10-19 00:05:52
阅读次数:
194
本文讲解4道关于permutation的题目。
1. Permutation:输出permutation——基础递归
2. Permutation Sequence: 输出第k个permutation——推理
3. Next Permutation:给定一个permutation中的序列,求字典序它的下一个permutation是什么——逻辑推理
4. Permutation II:和第一题有细微的差别: 对于一个可能有重复元素的数组输出所有permutation——有条件dfs...
分类:
其他好文 时间:
2014-10-18 19:45:40
阅读次数:
224
Problem Description
Given an N * M matrix with each entry equal to 0 or 1. We can find some rectangles in the matrix whose entries are all 1, and we define the maximum area of such rectangle as this ...
分类:
移动开发 时间:
2014-10-17 23:26:50
阅读次数:
264
Inside Deep Zoom –Part II: Mathematical AnalysisWelcome to part two ofInside Deep Zoom. Inpart one, I talked about the very basic ideas behind Deep Zo...
分类:
Web程序 时间:
2014-10-17 13:45:51
阅读次数:
263
[leetcode]Given n, generate all structurally unique BST's (binary search trees) that store values 1...n....
分类:
其他好文 时间:
2014-10-17 12:08:07
阅读次数:
165
LeetCode:SubsetsGiven a set of distinct integers,S, return all possible subsets.Note:Elements in a subset must be in non-descending order.The solution...
分类:
其他好文 时间:
2014-10-17 10:27:24
阅读次数:
293
最新版管道应力分析CAESAR II 2014 v7.00 WinXP_7 凯撒2CAESAR II 2013 R1 v6.10 管道设计应力分析 新增功能CAESAR Ⅱ 2011 v5.30.2 WinXP_7-ISO 1DVD(最新完全破解版,适用于Win7 32位和64位系统。管道应力分析....
【题目】
Given a binary tree, return the bottom-up level order traversal of its nodes' values. (ie, from left to right, level by level from leaf to root).
For example:
Given binary tree {3,9,20,#...
分类:
其他好文 时间:
2014-10-16 18:00:42
阅读次数:
245
Americans are usually 1) tolerant of non-native speakers who have some 2) trouble understanding English. But they become 3)annoyed when a person pret....
分类:
其他好文 时间:
2014-10-16 01:42:21
阅读次数:
242
题目:hdoj 3376 Matrix Again
题意:给出一个m*n的矩阵,然后从左上角到右下角走两次,每次只能向右或者向下,出了末尾点其他只能走一次,不能交叉,每次走到一个格子拿走这个格子中的数字,求价值最大?
分析:很明显费用流,开始想的到一种建图方案,但是那样的话流量全为负值的话会成一个环,所以果断换了。
建图方案是:
首先拆点,每个点拆成两个i 和 ii ,建边...
分类:
其他好文 时间:
2014-10-15 18:56:11
阅读次数:
244