首页 > 其他分享 >[LeetCode][309]best-time-to-buy-and-sell-stock-with-cooldown

[LeetCode][309]best-time-to-buy-and-sell-stock-with-cooldown

时间:2023-08-29 09:22:26浏览次数:50  
标签:sell 309 buy transactions cooldown prices stock

Content

You are given an array prices where prices[i] is the price of a given stock on the ith day.

Find the maximum profit you can achieve. You may complete as many transactions as you like (i.e., buy one and sell one share of the stock multiple times) with the following restrictions:

  • After you sell your stock, you cannot buy stock on the next day (i.e., cooldown one day).

Note: You may not engage in multiple transactions simultaneously (i.e., you must sell the stock before you buy again).

 

Example 1:

Input: prices = [1,2,3,0,2]
Output: 3
Explanation: transactions = [buy, sell, cooldown, buy, sell]

Example 2:

Input: prices = [1]
Output: 0

 

Constraints:

  • 1 <= prices.length <= 5000
  • 0 <= prices[i] <= 1000
Related Topics
  • 数组
  • 动态规划

  • 标签:sell,309,buy,transactions,cooldown,prices,stock
    From: https://www.cnblogs.com/shea24/p/17663885.html
  • 相关文章

    • 题解 ABC309Ex【Simple Path Counting Problem】
      好好玩的题。设普通生成函数\(F_i\),其中\([z^k]F_i\)表示从所有起点走到\((i,k)\)的方案数。特别地,\([z^k]F_1=\sum\limits_{a\inA}[a=k]\)。注意到\(F_i=(z^{-1}+1+z)F_{i-1}\)几乎成立,但是在\([z^1]F_i\)和\([z^M]F_i\)处不成立。尝试对\(F_i\)进行改造:\[[z^k......
    • [LeetCode][121]best-time-to-buy-and-sell-stock
      ContentYouaregivenanarraypriceswhereprices[i]isthepriceofagivenstockontheithday.Youwanttomaximizeyourprofitbychoosingasingledaytobuyonestockandchoosingadifferentdayinthefuturetosellthatstock.Returnthemaximu......
    • AtCoder-ABC-309 C - Medicine
      C-Medicine题目大意:给n种药,第i种药吃\(a_i\)天,每天\(b_i\)粒。问最早在第几天,当天要吃的药≤K。\(1<=n<=3*10^5\)\(0<=k<=10^9\)\(1<=a_i,b_i<=10^9\)解题思路首先了解了n种药,每次都是从第一天开始,持续\(a_i\)天,所以我当时直接想到用差分来做,数组初始全为......
    • mysql在开启group_replication后,报错ERROR 3092,This member has more executed transa
      问题描述:mysql在开启group_replication后,报错ERROR3092,Thismemberhasmoreexecutedtransactionsthanthosepresentinthegroup,如下所示:数据库:MySQL8.0.27系统:rhel7.31、异常重现Slave01[(none)]>startgroup_replication;ERROR3092(HY000):Theserverisnotc......
    • [ABC309G] - Ban Permutation 题解
      [ABC309G]-BanPermutation题解题目描述求长为\(N(N\leq100)\)且满足以下条件的排列\(P=(P_1,P_2,...,P_N)\)的个数,模\(998244353\):\(\forall1\leqi\leqN\),\(|P_i-i|\geqX(X\leq5)\)。思路首先拆绝对值,得到:\[P_i\geX+i\veeP_i\leX-i\]数数题除了排列......
    • POJ - Buy Tickets
      Smiling&Weeping----你看这个人,嘴里说着喜欢我却又让我这么难过DescriptionRailwayticketsweredifficulttobuyaroundtheLunarNewYearinChina,sowemustgetupearly......
    • spartan-6 ax309学习日记合集1
      一、环境安装配置两个开发环境ISE和modelsim,我安装的是ISE14.7(最新版,不再更新,由于Spartan-7及以上才可以使用vivado,故只能使用ISE)和modelsim10.1c(注意一定有c)二、流水灯程序编写学习因为我没有verilog基础,并且是初次接触FPGA开发板,没找到直接的教程,故开始打算先学一点verilog......
    • [abc309 F] Box in Box
      F-BoxinBox首先,每个长方体的\(h,w,d\)都是可以任意互换的,所以我们考虑用\(a_0,a_1,a_2\)来代替它们(\(a_0\leqa_1\leqa_2\))然后可以发现一个规律,我们肯定是用\(a_0\)和\(a_0\)比较,\(a_1\)和\(a_1\)比较,\(a_2\)和\(a_2\)比较那么现在显然就是三位偏序,可以上\(CDQ\)了,先对\(......
    • AtCoder Beginner Contest 309 - D(最短路)
      目录D-AddOneEdge法一:dijkstra法二:BFS+队列题目传送门:abc309前面的简单题就不放了D-AddOneEdge题意:给你一个无向图图,分为两个连通块,一个顶点数为n1(1~n1),一个顶点数为n2(n1+1~n1+n2),图中共有m条边。如果现在在两个连通块之间连接一条边,那么顶点1与顶点n1+n2......
    • Atcoder ABC 309 F
      AtcoderABC309F题意n个盒子,长宽高为\(x,y,z,\)(长宽高是相对的,可以任意调换),问是否有一个盒子可以完全容纳另一个盒子,即存在一个\(A_i={x_i,y_i,z_i},A_j={x_j,y_j,z_j}\),使得\(x_i<x_j,y_i<y_j,z_i<z_j\)思路思考一个简单的问题:对于二元组\((x,y)\),我们怎么确定存在两......