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. 传智 Python基础班+就业班+课件 【最新完整无加密视频课程】

    点击了解更多Python课程>>> 传智 Python基础班+就业班+课件 [最新完整无加密视频课程] 直接课程目录 python基础 linux操作系统基础) 1-Linux以及命 ...

  2. Python基础——异常

    捕捉所有异常 for i in range(10): try: input_number=input('write a number') if input_number=='q': break res ...

  3. python getopt模块使用方法

    python中 getopt 模块,是专门用来处理命令行参数的 getop标准格式: 函数getopt(args, shortopts, longopts = []) shortopts 是短参数   ...

  4. MySQL使用yum安装

    1.下载mysql的repo源 $ wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm 2.安装mysql-comm ...

  5. JS实现——Base64编码解码,带16进制显示

    在网上找了个JS实现的Base64编码转换,所以就想自己研究下,界面如下: 将代码以BASE64方式加密.解密 请输入要进行编码或解码的字符: 编码结果以ASCII码16进制显示 解码结果以ASCII ...

  6. 数据库学习网站和linux学习网站

    Oracle ITPub论坛 http://www.itpub.net 著名IT技术论坛.尤以数据库技术闻名. ITPUB论坛的前身应该是建立在 smiling 的 oracle小组,他们搬家前的主页 ...

  7. Selenium WebDriver- 指定页面加载时间

    #encoding=utf-8 import unittest import time from selenium import webdriver from selenium.webdriver i ...

  8. 大数据学习——scala数组

    package com import scala.collection.mutable.ArrayBuffer /** * Created by Administrator on 2019/4/8. ...

  9. Sonar - 部署常见问题及解决方法

    1. sonarqube启动报错,查看es.log如下: 问题原因:sonarqube不能使用root用户启动 解决方法: (1)更改sonarqube所属用户权限 chown -R gold:gol ...

  10. Python学习-day4

    学习装饰器,首先听haifeng老师讲解了一下准备知识. 1.函数即变量 2.高阶函数+嵌套函数==>装饰器 装饰器的作用是在,1)不改变源代码,2)不改变原函数的调用方式的前提下为函数增加新的 ...