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

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

LEETCODE--Best Time to Buy and Sell Stock II

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

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; }};
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: av成人在线电影 | 欧美性生活区 | 亚洲精品久久久久久久久久 | 蜜桃视频在线观看免费 | 欧美成人精品一区二区三区 | 日本免费aaa观看 | 露脸各种姿势啪啪的清纯美女 | 毛片一级免费看 | 性高跟鞋xxxxhd4kvideos | 日本教室三级在线看 | 美女视频免费一区二区 | 香蕉黄色网 | 午夜视频色 | 337p粉嫩大胆噜噜噜亚瑟影院 | 未成年人在线观看 | 蜜桃久久一区二区三区 | 香蕉久久久精品 | 久草在线视频在线 | 操嫩草| 久久99国产视频 | av影院在线播放 | 午夜久久久精品一区二区三区 | 麻豆国产网站 | 手机视频在线播放 | 日本特级a一片免费观看 | 操碰97| 久久久精品精品 | 斗罗破苍穹在线观看免费完整观看 | 男女污污视频网站 | 久久久久久久国产a∨ | 91成人免费在线视频 | 国产一区二区三区手机在线 | 爱草在线| 亚洲最新色 | 成人在线免费小视频 | 久草成人在线观看 | 毛片在线视频在线播放 | 欧美五月婷婷 | 免费看日韩片 | 国产午夜精品理论片a级探花 | 久草视频在线资源 |