Best Time to Buy and Sell Stock

题目大意;给定数组a[..],求解max a[j]-a[i]    j>i

解决思路:将数组a的相邻值相减(右边减左边)变换成数组b,上述问题

转变成了求数组b的子数组最大和问题。

public int maxEndingHere=0,maxSoFar=0;

for (int k=0;k<n;k++){

int s=0;

int t=n-1;

while (s<t){

int tmp=matrix [k][s];

matrix[]k][s]=martix[k][t];

matrix[k][t]=tmp;

s++;

t--;

}

}

return ;

}

};

LeetCode Best to buy and sell stock的更多相关文章

  1. [LeetCode] Best Time to Buy and Sell Stock with Cooldown 买股票的最佳时间含冷冻期

    Say you have an array for which the ith element is the price of a given stock on day i. Design an al ...

  2. [LeetCode] Best Time to Buy and Sell Stock IV 买卖股票的最佳时间之四

    Say you have an array for which the ith element is the price of a given stock on day i. Design an al ...

  3. [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 al ...

  4. [LeetCode] Best Time to Buy and Sell Stock II 买股票的最佳时间之二

    Say you have an array for which the ith element is the price of a given stock on day i. Design an al ...

  5. [LeetCode] Best Time to Buy and Sell Stock 买卖股票的最佳时间

    Say you have an array for which the ith element is the price of a given stock on day i. If you were ...

  6. 121. Best Time to Buy and Sell Stock (一) leetcode解题笔记

    121. Best Time to Buy and Sell Stock Say you have an array for which the ith element is the price of ...

  7. leetcode 第188题,我的解法,Best Time to Buy and Sell Stock IV

    <span style="font-family: Arial, Helvetica, sans-serif; background-color: rgb(255, 255, 255) ...

  8. LEETCODE —— Best Time to Buy and Sell Stock II [贪心算法]

    Best Time to Buy and Sell Stock II Say you have an array for which the ith element is the price of a ...

  9. LeetCode:Best Time to Buy and Sell Stock I II III

    LeetCode:Best Time to Buy and Sell Stock Say you have an array for which the ith element is the pric ...

随机推荐

  1. 二、latex简单使用

    安装成功则可显示如图所示的信息. 用记事本便可完成整个过程. 命令如图所示: 首先用documentclass命令引入一个文档类,比如引入article文档类,主要用于撰写论文.{}中的内容表示命令的 ...

  2. docker构建本地仓库后,无法登陆解决办法(CentOS/Ubuntu)

    docker版本为:Server Version: 1.12.6 从dockerhub上下载最新的registry镜像. 首先.构建registry 1.下载registry镜像 docker pul ...

  3. 内存地址 id

    def a(): return b def b(): print('666')c = a()print(c) #打印16进制的内存地址print(b) #打印16进制的内存地址print (id(c) ...

  4. 星型数据仓库olap工具kylin介绍和简单使用示例

    本文转载自:https://www.cnblogs.com/hsydj/p/4515057.html 星型数据仓库olap工具kylin介绍 星型数据仓库olap工具kylin介绍 数据仓库是目前企业 ...

  5. hdu4916 Count on the path

    调了好久.... •把树视为以1为根的有向树,然后将1删除 •原树变为一个森林,并且任一棵树的根节点均为原树中1的子节点 •只需要考虑最小编号前3小的三棵树 •记f[x][y]为去掉x和y两棵树后的最 ...

  6. 51Nod 博弈模板题

    连刷3道博弈模板题,算是稍微学习了以下三个经典博弈了.推荐一个博客. 第一道模板:Bash博弈——同余理论 1066 Bash游戏 基准时间限制:1 秒 空间限制:131072 KB 分值: 0 难度 ...

  7. Fast Matrix Calculation HDU - 4965

    One day, Alice and Bob felt bored again, Bob knows Alice is a girl who loves math and is just learni ...

  8. 使用 mysqladmin debug 查看死锁信息

    使用 mysqladmin debug 查看死锁信息 mysqladmin -S /mysql/data/mysql.sock debug 然后在error日志中,会看到: 11 lock struc ...

  9. java中Map集合的常用方法

    Map集合和Collection集合的区别 Map集合是有Key和Value的,Collection集合是只有Value. Collection集合底层也是有Key和Value,只是隐藏起来. V p ...

  10. ssm回顾笔记(一)

    这两天来到了农银,这边即将进行的一个项目是将ssh框架的电商项目迁移到springboot+ssm框架上,所以我基本上是三门技术在同时进行学习,当然以前学过ssm,现在只是回顾. spring 注解 ...