LeetCode Best to buy and sell stock
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的更多相关文章
- [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 ...
- [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 ...
- [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 ...
- [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 ...
- [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 ...
- 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 ...
- leetcode 第188题,我的解法,Best Time to Buy and Sell Stock IV
<span style="font-family: Arial, Helvetica, sans-serif; background-color: rgb(255, 255, 255) ...
- 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 ...
- 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 ...
随机推荐
- 经验分享 | 如何拿到自己满意的offer?
本文阅读时间约16分钟 最近两年,人工智能(AI)就像一个点石成金的神器,所有的行业,创业公司,或是求职,只要沾着这个词,多少有点脚踩五彩祥云的感觉,故事来了,融资来了,高薪来了. 于是,越来越多的人 ...
- redis示例 - 限速器,计时器
INCR INCR key 将 key 中储存的数字值增一. 如果 key 不存在,那么 key 的值会先被初始化为 0 ,然后再执行 INCR 操作. 如果值包含错误的类型,或字符串类型的值不能表示 ...
- nrm 使用
全局安装 npm i nrm -g 全局安装nrm nrm ls 查看镜像地址: npm ---- https://registry.npmjs.org/ cnpm --- http://r.c ...
- zw量化交易·实盘操作·系列培训班
参见: <zw量化交易·实盘操作·系列培训班> http://blog.sina.com.cn/s/blog_7100d4220102w0q5.html
- 2017.11.10 重读C++ Primer
第二章 变量和变量类型 1. C++ 算数类型 bool 布尔 最小尺寸未定义 char 字符 8位 wchar_t ...
- Flask最强攻略 - 跟DragonFire学Flask - 第十五篇 Flask-Script
其实本章就是为下一章做的铺垫啦,但是也要认真学习哦 Flask-Script 从字面意思上来看就是 Flask 的脚本 是的,熟悉Django的同学是否还记得Django的启动命令呢? python ...
- Class_fourh_异常总结
使用try,catch,finally.检查指点检查点是否错误: try里填入监测的内容 catch 小括号里放类型错误 判断try里出现的错误是哪一类错误 中括号里放 输出内容 在控制台上输出错误 ...
- 基于ABP模块组件与依赖注入组件的项目插件开发
注意,阅读本文,需要先阅读以下两篇文章,并且对依赖注入有一定的基础. 模块系统:http://www.cnblogs.com/mienreal/p/4537522.html 依赖注入:http://w ...
- SCI_Call_Bsw_SetPwmMotorGroupB
Sci_Bsw.c -- definition MotorGroupB_cfg.c -- called in LatchControl_Magna.c: extern uint16 Sci_DRead ...
- Solr和Lucene的区别?
1.Lucene 是工具包 是jar包 2.Solr是索引引擎服务 War 3.Solr是基于Lucene(底层是由Lucene写的) 4.上面二个软件都是Apache公司由java写的 5.Luc ...