麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

首頁 > 學院 > 開發設計 > 正文

LEETCODE--Best Time to Buy and Sell Stock II

2019-11-14 09:18:18
字體:
來源:轉載
供稿:網友

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 as many transactions as you like (ie, buy one and sell one share of the stock multiple times). However, you may not engage in multiple transactions at the same time (ie, you must sell the stock before you buy again).

參考解釋

class Solution {public: int maxProfit(vector<int>& prices) { int len = prices.size(); int profit = 0; for(int i = 1; i < len; i++){ profit += max(prices[i]-prices[i-1], 0); } return profit; }};

方法二:略麻煩

class Solution {public: int maxProfit(vector<int>& prices) { int i = 0; int j = 1; int len = prices.size(); int profit = 0; int pre; while(j < len){ pre = prices[j-1]; if(pre < prices[j]){ j++; if(j == len) profit += prices[j-1] - prices[i]; }else{ cout << pre << endl; profit += pre - prices[i]; i = j; j++; } } return profit; }};
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 欧美日韩免费一区 | 2017亚洲男人天堂 | 国产亚洲精品久久久久久久久久 | 欧美a一 | 欧美一级毛片美99毛片 | 日本不卡视频在线观看 | 性高湖久久久久久久久aaaaa | 99精美视频 | 一区二区三区欧美在线观看 | 91精品观看91久久久久久国产 | 91在线视频网址 | 日本成年免费网站 | 黄色7777| 免费看黄色一级大片 | 特黄一级小说 | 玖草在线资源 | 久久久久亚洲精品国产 | 色偷偷一区 | 欧美四级在线观看 | 久久精精品 | 一级空姐毛片 | 操操操日日日干干干 | 久久福利精品 | 午夜精品福利视频 | 高清做爰免费无遮网站挡 | 国产成人综合在线观看 | 天天操天天骑 | 国产视频在线观看一区二区三区 | 羞羞网站| 久久精品国产99久久久古代 | 免费一级欧美 | a网站在线 | 日韩精品羞羞答答 | 手机免费看一级片 | 国产资源在线播放 | 免费黄色小网站 | 高清做爰免费无遮网站挡 | 日韩视频www| 国产一区二区不卡视频 | 4p嗯啊巨肉寝室调教男男视频 | 精品在线免费播放 |