博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Best Time to Buy and Sell Stock III
阅读量:4075 次
发布时间:2019-05-25

本文共 749 字,大约阅读时间需要 2 分钟。

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 algorithm to find the maximum profit. You may complete at most two transactions.

Note:
You may not engage in multiple transactions at the same time (ie, you must sell the stock before you buy again).

java代码:

public class Solution {    public int maxProfit(int[] prices) {        int n = prices.length;    if(n<2) return 0;    //first transaction's max profit    int[] fmp = new int[n];    fmp[0] = 0;    int minPrice = prices[0];    for(int i=1; i
=0; i--){ maxPrice = Math.max(maxPrice, prices[i]); smp[i] = Math.max(smp[i+1], maxPrice-prices[i]); } int profix = 0; for(int i=0; i

转载地址:http://bpuni.baihongyu.com/

你可能感兴趣的文章
Oracle 异机恢复
查看>>
Oracle 12C DG 搭建(RAC-RAC/RAC-单机)
查看>>
Truncate 表之恢复
查看>>
Oracle DG failover 后恢复
查看>>
为什么很多程序员都选择跳槽?
查看>>
mongdb介绍
查看>>
Yotta企业云盘助力科技行业创高峰
查看>>
Yotta企业云盘更好地为教育行业服务
查看>>
Yotta企业云盘怎么帮助到能源化工行业
查看>>
企业云盘如何助力商业新发展
查看>>
医疗行业运用企业云盘可以带来什么样的提升
查看>>
媒体广告业如何运用云盘提升效率
查看>>
IOS开发的开源库
查看>>
Jenkins - sonarqube 代码审查
查看>>
Jenkins + Docker + SpringCloud 微服务持续集成(一)
查看>>
Jenkins + Docker + SpringCloud 微服务持续集成 - 单机部署(二)
查看>>
Jenkins + Docker + SpringCloud 微服务持续集成 - 高可用集群部署(三)
查看>>
Linux 粘滞位 suid sgid
查看>>
C#控件集DotNetBar安装及破解
查看>>
Winform皮肤控件IrisSkin4.dll使用
查看>>