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. oracle 死锁

    oracle 死锁 --查用户名,查客户端机器 SELECT distinct s.username,s.MACHINE, s.sid||','||s.serial# FROM gv$session ...

  2. eclipse无法断点调试JDK源码的问题

    最近换了新版的eclipse,在jdk源码里面,打断点发现无法进入源码调试,程序直接跳过,已查资料发现自己eclipse配置的是jre环境的. 此处要配成jdk目录才有效 打开preferences, ...

  3. 《CSS世界》读书笔记(七)

    <!-- <CSS世界> 张鑫旭著 --> 替换元素 根据是否具有可替换内容,我们可以把元素分为替换元素和非替换元素. <img>.<object>.& ...

  4. PHP防止网页快速刷新+代理ip访问

    前几天网站收到了一些CC攻击,比较郁闷...这里分享一下,防止网页自动刷新的方法以及阻止代理IP访问网站的方法,代码是分开的,两个功能,需要那个用那个,可以自定义时间间隔,这个代码不止可以防CC攻击, ...

  5. Dijkstra双栈算术表达式求值

    在看algs4的时候偶然发现了这个算法,又回顾了一遍当时数据结构课程里讲过的知识,当时很不在意.迟早是要还的,哎 用python实现了,比较麻烦的是我现在没有解决bash传参的问题,''(" ...

  6. ogg跳过某个RBA

    1.从库复制进程报如下错误 *************************************************************************              ...

  7. Codeforces 438E The Child and Binary Tree - 生成函数 - 多项式

    题目传送门 传送点I 传送点II 传送点III 题目大意 每个点的权值$c\in {c_{1}, c_{2}, \cdots, c_{n}}$,问对于每个$1\leqslant s\leqslant ...

  8. Springboot解决war包放到Tomcat服务器上404的特殊情况

    Springboot解决war包放到Tomcat服务器上404的特殊情况 原文链接:https://www.cnblogs.com/blog5277/p/9330577.html 原文作者:博客园-- ...

  9. 浅谈JS中的typeof和instanceof的区别

    JS中的typeof和instanceof常用来判断一个变量是否为空,或者是什么类型. typeof typeof运算符返回一个用来表示表达式的数据类型的字符串. typeof一般返回以下几个字符串: ...

  10. angular --- s3core移动端项目

    因为记性不好的原因做个草稿笔记 app.js中 var myApp = angular.module('myApp',['ui.router','oc.lazyLoad','ngAnimate','数 ...