!!!!!122. Best Time to Buy and Sell Stock II
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).
=======================
股票交易问题II
题目:与I不同的地方是,可以做尽可能做的交易,
这一次你可以买一只股票,卖一只股票多次;但是你不能在同一时间进行多次交易,
就是说你必须在你买股票之前,卖掉所有到的股票。
[]
=========
code:
class Solution {
//这一次你可以买一只股票,卖一只股票多次;但是你不能在同一时间进行多次交易,
//就是说你必须在你买股票之前,卖掉所有的股票
public:
int maxProfit(vector<int>& prices) {
//举个例子[5,1,4,5,3,4,5]
// [0,3,1,0,1,1]
//j就是说所有能赚钱的机会,你都能抓住
//而不是只能作一次交易,只能赚5-1=4
int length = prices.size();
int total = ;
for(int i = ;i<length;i++){
if(prices[i]>prices[i-]){
total += prices[i]-prices[i-];
}
}//
return total;
}
};
!!!!!122. Best Time to Buy and Sell Stock II的更多相关文章
- 31. leetcode 122. Best Time to Buy and Sell Stock II
122. Best Time to Buy and Sell Stock II Say you have an array for which the ith element is the price ...
- leetcode 121. Best Time to Buy and Sell Stock 、122.Best Time to Buy and Sell Stock II 、309. Best Time to Buy and Sell Stock with Cooldown
121. Best Time to Buy and Sell Stock 题目的要求是只买卖一次,买的价格越低,卖的价格越高,肯定收益就越大 遍历整个数组,维护一个当前位置之前最低的买入价格,然后每次 ...
- 122. Best Time to Buy and Sell Stock II@python
Say you have an array for which the ith element is the price of a given stock on day i. Design an al ...
- leetcode:122. Best Time to Buy and Sell Stock II(java)解答
转载请注明出处:z_zhaojun的博客 原文地址 题目地址 Best Time to Buy and Sell Stock II Say you have an array for which th ...
- 【刷题-LeetCode】122 Best Time to Buy and Sell Stock II
Best Time to Buy and Sell Stock II Say you have an array for which the ith element is the price of a ...
- 【一天一道LeetCode】#122. Best Time to Buy and Sell Stock II
一天一道LeetCode 本系列文章已全部上传至我的github,地址:ZeeCoder's Github 欢迎大家关注我的新浪微博,我的新浪微博 欢迎转载,转载请注明出处 (一)题目 Say you ...
- [LeetCode] 122. Best Time to Buy and Sell Stock II 买卖股票的最佳时间 II
Say you have an array for which the ith element is the price of a given stock on day i. Design an al ...
- LeetCode 122. Best Time to Buy and Sell Stock II (stock problem)
Say you have an array for which the ith element is the price of a given stock on day i. Design an al ...
- leetcode 122. Best Time to Buy and Sell Stock II ----- java
Say you have an array for which the ith element is the price of a given stock on day i. Design an al ...
随机推荐
- 读《程序员的SQL金典》[2]--函数
一.数学函数 1.RAND SELECT RAND () ---0.302870228294199 取0-1之间的随机小数. 2.小数取整 CEILINT(data)舍掉小数部分并向上取整. FLOO ...
- mac 下安装jmeter
1.http://jmeter.apache.org/download_jmeter.cgi 下载jmeter 2.解压包 3.进入解压目录/bin/ 4.sh jmeter
- CodeForces 688C-NP-Hard Problem
题意: 给你一个无向图,判断是否能够构成一个二分图,如果能的话,输出二分图左边的集合和右边的集合 分析: 先给每一个顶点的color初始化-1,表示没有被染色,用vector数组v[a],表示元素a所 ...
- JEECMS v8 发布,java 开源 CMS 系统
JEECMSv8 是国内java开源CMS行业知名度最高.用户量最大的站群管理系统,支持栏目模型.内容模型交叉自定义.以及具备支付和财务结算的内容电商为一体: 对于不懂技术的用户来说,只要通过后台的 ...
- sublime开发php必备工具集合(mac)
sublime开发php必备工具集合(Mac) 相关链接:http://benmatselby.github.io/sublime-phpcs/ 目标: 直接在sublime中运行php代码 按PSR ...
- Android RecyclerView单击、长按事件标准实现:基于OnItemTouchListener + GestureDetector
Android RecyclerView单击.长按事件:基于OnItemTouchListener + GestureDetector标准实现 Android RecyclerView虽然拥有L ...
- JSP 动作元素
JSP动作元素 1. 动作元素分类 用来动态的包含文件.网页跳转及使用JavaBean组件等. 语法:<jsp:XXX />或者<jsp:XXX></jsp:XXX&g ...
- @proprety数组字典字符串用copy和strong区别(深浅拷贝)
//// @proprety数组字典字符串用copy和strong区别(深浅拷贝).h// IOS笔记//// /* _proprety________copy_strong_________h ...
- Linux设计准则
计算机体系结构: 运算器 控制器 存储器,内存,编址 输出设备 输入设备 Linux内核功能: 进程管理内存管理文件系统网络功能硬件驱动安全机制 Linux的基本原则: 1.由目的单一的小程序组成: ...
- Linux——常用命令详解
文件处理命令:ls -l drwxr-xr-x 文件 d rwx r-x r-x d:表示directory 是一个目录 - 表示二进制文件 l 表示链接文件l ...