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

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

LEETCODE--Best Time to Buy and Sell Stock II

2019-11-14 10:43:44
字體:
來源:轉載
供稿:網友

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; }};
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 国产一区二区视频观看 | 免费视频aaa | a一级黄色大片 | 精品一区二区三区毛片 | 免费久久久久久 | 成人国产精品一区 | 羞羞答答www网站进入 | 国产欧美在线观看不卡一 | 青草视频在线观看视频 | 成人综合一区二区 | 久久久久久久久久久av | 5a级毛片| 成人在线国产 | 伊人亚洲精品 | 一道本不卡一区 | av电影在线网站 | av久草| 午夜小电影 | 中文字幕亚洲一区二区三区 | 精品国产乱码一区二区 | 免费毛片视频 | 亚洲视频精选 | 色就色 综合偷拍区91网 | 玩偶姐姐 在线观看 | 国产大片中文字幕在线观看 | 精品国产一级毛片 | 九一免费版在线观看 | 日韩免费黄色 | av观看网站 | 黄网站在线免费 | 欧美日本色 | 中国杭州少妇xxxx做受 | 成人综合一区二区 | 欧美成人精品一级 | 国产精品刺激对白麻豆99 | 黄色毛片一级视频 | 久草视频2| 欧美日韩亚洲国产精品 | 日本一道aⅴ不卡免费播放 视屏一区 | 极品大长腿啪啪高潮露脸 | 在线成人www免费观看视频 |