LeetCode OJ--Best Time to Buy and Sell Stock II
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的更多相关文章
- [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】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 ...
- 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 【 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 ...
- 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 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 ...
- LeetCode OJ - Best Time to Buy and Sell Stock
版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/xiezhihua120/article/details/32939749 Say you have ...
- 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 ...
- 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 ...
- 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 ...
随机推荐
- 为什么要用 ORM? 和 JDBC 有何不一样?
orm是一种思想,就是把object转变成数据库中的记录,或者把数据库中的记录转变objecdt,我们可以用jdbc来实现这种思想,其实,如果我们的项目是严格按照oop方式编写的话,我们的jdbc程序 ...
- city Engine 建模
基本操作介绍 界面布局,文件组织 五个常见图层 常见规则,替换思想
- Do not pour out HDU - 5954 数学积分
题目:题目链接 思路:纯高等数学问题,不过不是很好积分,具体积分思路及过程参考大佬博客——https://blog.csdn.net/danliwoo/article/details/53002695 ...
- MIP启发式算法:Variable fixing heuristic
*本文主要记录及分享学习到的知识,算不上原创 *参考文章见链接. 本文简单介绍一下Variable fixing heuristic,这个算法同样以local search为核心框架,它的特点在于定义 ...
- selenium2中TestNG相关解释
testNg官网:http://testng.org/doc/documentation-main.html 新建testNG class的时候,同时也新建了一个TestNG.xml的文件. 此xml ...
- base64转图片
y一个简单的工具类,附上: /** * @param imgStr 图片的base64 * @param path 将要生成的地址 * @return */ public static boolean ...
- DataContext.ExecuteQuery的两种方法调用
ExecuteQuery主要用于DataContext类直接执行SQL语句的查询,在MSDN上有两种执行方法,下面为两种方法的不同调用: 1.ExecuteQuery<TResult>(S ...
- MySQL中的DDL(Data Definition Language,数据定义语言)
create(创建表) 标准的建表语句: create table [模式名.]表名 ( #可以有多个列定义 columnName1 dataType [default expr(这是默认值)], . ...
- python - log日志
# -*- coding:utf-8 -*- ''' @project: jiaxy @author: Jimmy @file: study_logging.py @ide: PyCharm Comm ...
- day03_11 if语句实现猜年龄01
老男孩猜年龄游戏 age_of_princal = 56 guess_age = int( input(">>:") ) #以下为伪代码 ''' if guess_ag ...