http://oj.leetcode.com/problems/best-time-to-buy-and-sell-stock-ii/

第二问,是说可以进行无数次买卖。

贪心法

#include <iostream>
#include <vector>
using namespace std; class Solution {
public:
int maxProfit(vector<int> &prices) {
if(prices.empty())
return NULL;
if(prices.size()==)
return ;
int ans = ;
for(int i = ;i<prices.size();i++)
{
if(prices[i]>prices[i-])
ans = ans - prices[i-] +prices[i];
}
return ans;
}
}; int main()
{
Solution myS;
vector<int> price;
price.push_back();
price.push_back();
price.push_back();
price.push_back();
price.push_back();
price.push_back();
price.push_back(-);
myS.maxProfit(price);
return ;
}

LeetCode OJ--Best Time to Buy and Sell Stock II的更多相关文章

  1. [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 ...

  2. 【leetcode】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 ...

  3. 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 ...

  4. leetcode 【 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 a ...

  5. 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 ...

  6. [LeetCode OJ] Best Time to Buy and Sell Stock I

    Say you have an array for which the ith element is the price of a given stock on day i. If you were ...

  7. LeetCode OJ - Best Time to Buy and Sell Stock

    版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/xiezhihua120/article/details/32939749 Say you have ...

  8. LeetCode 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 al ...

  9. 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 ...

  10. Java [Leetcode 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 ...

随机推荐

  1. pandas中数据聚合【重点】

    数据聚合 数据聚合是数据处理的最后一步,通常是要使每一个数组生成一个单一的数值. 数据分类处理: 分组:先把数据分为几组 用函数处理:为不同组的数据应用不同的函数以转换数据 合并:把不同组得到的结果合 ...

  2. 896. Monotonic Array

    An array is monotonic if it is either monotone increasing or monotone decreasing. An array A is mono ...

  3. destoon 屏蔽会员组,让个人,游客不显示

    include/post.fun.php  文件的group_select函数增加 排除参数 except function group_select($name = 'groupid', $titl ...

  4. Python json和simplejson的使用

    在Python中,json数据和字符串的转换可以使用json模块或simplejson模块. json从Python2.6开始内置到了Python标准库中,我们不需要安装即可直接使用. simplej ...

  5. POJ:2632-Crashing Robots

    Crashing Robots Time Limit: 1000MS Memory Limit: 65536K Description In a modernized warehouse, robot ...

  6. 利用Windbg深入理解变量的存储模型

    下面的是一个简单的测试程序,基本包括了所有的变量类型,包括静态的,常量的,全局的,本地的,还有new出来的 #include <iostream> using namespace std; ...

  7. HDU 5402 模拟 构造 Travelling Salesman Problem

    题意: 有一个n * m的数字矩阵,每个格子放着一个非负整数,从左上角走到右下角,每个格子最多走一次,问所经过的格子的最大权值之和是多少,并且输出一个路径. 分析: 如果n和m有一个是偶数的话,那么只 ...

  8. python基础学习笔记——循环语句(while、for)

    while 循环 流程控制语句 while 1.基本循环 while 条件: # 循环体 # 如果条件为真,那么循环则执行 # 如果条件为假,那么循环不执行   2.break break 用于退出当 ...

  9. dotnet core 运行程序注意事项

    .net core 程序 debug版本无法直接运行,因为没有相关的dll,只有在进入项目文件夹那一层,执行 dotnet run 来运行,会自动链接 当前用户的个人文件夹下的 .nuget/.pac ...

  10. 配置hibernate常见问题

    连接MySql时出现:The server time zone value '�й���׼ʱ��' is unrecognized or represents more than one time z ...