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. 揭开yield关键字的神秘面纱

    写在前言 经常会看见,python函数中带有yield关键字,那么yield是什么,有什么作用? 答案:可以理解yield是一个生成器: 作用:遇到yield关键字,函数会直接返回yield值,相当于 ...

  2. 强迫症犯了,忍不住赞一下slf4j包Logger.java的优雅代码

    如下是slf4j-api包下的Logger接口类里其中几个方法的声明: package org.slf4j; public interface Logger { /** * Log a message ...

  3. Flip Game (高斯消元 || dfs)

    Flip game is played on a rectangular 4x4 field with two-sided pieces placed on each of its 16 square ...

  4. mysql查询语句and,or

    where查询里,常用到and,or and SELECT field1, field2,...fieldN FROM table_name1, table_name2... WHERE condit ...

  5. C#调用endtask

    原文最早发表于百度空间2009-03-23 写这个小工具主要是因为自动化测试那边反馈了一个问题和endtask有关,结果写完之后发现这个问题从程序外部测试不了……c#调endtask主要也是用DllI ...

  6. Shell 变量、脚本参数

    定义变量:可将脚本或者多个命令定义成一个变量. ()格式n(){脚本命令}. 脚本常用参数 命令:seq –w 0 23 #以01开头往上的. 命令:echo –ne #输出n换行,e扩展. 命令:b ...

  7. Linux 系统日志

    查看日志服务 大部分Linux发行版默认的日志守护进程为 syslog,位于 /etc/syslog 或 /etc/syslogd 或/etc/rsyslog.d,默认配置文件为 /etc/syslo ...

  8. Android中的task和stack

    今天在重新理了一遍intent的过程中发现task是一个神奇的东西,而它又和stack有着很深的联系.task顾名思义是一个任务,但是这个任务可不一定只是来自一个app,比如我用微信来发一张图片,那么 ...

  9. FFT 快速傅里叶变换 学习笔记

    FFT 快速傅里叶变换 前言 lmc,ikka,attack等众多大佬都没教会的我终于要自己填坑了. 又是机房里最后一个学fft的人 早背过圆周率50位填坑了 用处 多项式乘法 卷积 \(g(x)=a ...

  10. CodeForces 518E Arthur and Questions(贪心 + 思维)题解

    题意:给你a1~an,k,要求a1 + ... + ak < a2 + .... + ak+1 < a3 + ... + ak+2 <...,然后这里的ai有可能是?,要求你填?的数 ...