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 ...
随机推荐
- 抓取html 生成图片
<!DOCTYPE html> <html> <head> <script type="text/javascript" ...
- 手把手教你安装mac版hadoop2.7.3教程
一.准备教程 1.jdk:版本在1.7.x以上就可以(因为hadoop2.x以上只支持1.7.x以上的jdk,我的是1.8的) 2.Hadoop:2.7.3 二.ssh的配置以及验证 配置ssh: 1 ...
- Newtonsoft.Json解析数组
以下是解析json数组: var jsonInfo=[{"name":"abc","id":"1","coun ...
- unittest改写传参方法
Python主要讲究简洁简单使用,所以它不像junit一样支持参数化测试,需要改装一下也可以传参.直接上代码实例 import unittest class ParametrizedTestCase( ...
- 项目中常用的javascript/jquery操作
1.判断复选框是否被选中? $("#cpuWindow").is(':checked'); 2.设置复选框被选中: $("#cpuWindow").prop(& ...
- 腾讯云服务器使用smtp发送邮件
问题:在腾讯云服务器上使用自编写的邮件服务失败.查其原因,是该邮件服务调用smtpclient.Send(mailMessage)时,出现错误:由于连接方在一段时间后没有正确答复或连接的主机没有反应, ...
- 《CSS世界》读书笔记(一)
<!-- <CSS世界> 张鑫旭 著 --> CSS世界构建的基石是HTML,而HTML最具代表的两个基石<div>和<span>正好是CSS世界中块级 ...
- 1-趣味解读DNS工作原理——转载疯猫网络科技
因为只要我们输入百度.腾讯.淘宝的名字,无论它们的服务器在哪里,历经多少轮查询,我们都能找到并访问之.这就是计算机网络中著名的域名系统DNS(Domain Name System),它能实现把一个网站 ...
- Linux 进程管理、系统状态查询
1.内存给进程一段空间让他启动,让内核通过cpu来管理它. 2.ps命令查看命令信息. 用户.pid号.使用cpu.使用内存.虚拟内存.真实内存.控制台.状态.启动时间.运行时间.名 USER PID ...
- Mybaties 实现批量修改
通常我们在做批量更新的时候都会用in 去操作,但in的数据量一上来,就变的缓慢了 修改方案: <update id="updateShufflingSeq" paramete ...