[LintCode] 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).
Given an example [2,1,2,0,1], return 2
LeetCode上的原题,请参见我之前的博客Best Time to Buy and Sell Stock II。
- class Solution {
- public:
- /**
- * @param prices: Given an integer array
- * @return: Maximum profit
- */
- int maxProfit(vector<int> &prices) {
- int res = , n = prices.size();
- for (int i = ; i < n - ; ++i) {
- if (prices[i] < prices[i + ]) {
- res += prices[i + ] - prices[i];
- }
- }
- return res;
- }
- };
[LintCode] Best Time to Buy and Sell Stock II 买股票的最佳时间之二的更多相关文章
- [LeetCode] 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] Best Time to Buy and Sell Stock III 买股票的最佳时间之三
Say you have an array for which the ith element is the price of a given stock on day i. Design an al ...
- [LintCode] Best Time to Buy and Sell Stock 买卖股票的最佳时间
Say you have an array for which the ith element is the price of a given stock on day i. If you were ...
- [LeetCode] Best Time to Buy and Sell Stock 买卖股票的最佳时间
Say you have an array for which the ith element is the price of a given stock on day i. If you were ...
- [LeetCode] 121. Best Time to Buy and Sell Stock 买卖股票的最佳时间
Say you have an array for which the ith element is the price of a given stock on day i. If you were ...
- [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 ...
- 27. Best Time to Buy and Sell Stock && Best Time to Buy and Sell Stock II && Best Time to Buy and Sell Stock III
Best Time to Buy and Sell Stock (onlineJudge: https://oj.leetcode.com/problems/best-time-to-buy-and- ...
- 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 pric ...
随机推荐
- ACM/ICPC 之 Dinic+枚举最小割点集(可做模板)(POJ1815)
最小割的好题,可用作模板. //Dinic+枚举字典序最小的最小割点集 //Time:1032Ms Memory:1492K #include<iostream> #include< ...
- (三)Netty源码学习笔记之boss线程处理流程
尊重原创,转载注明出处,原文地址:http://www.cnblogs.com/cishengchongyan/p/6160194.html 本文我们将先从NioEventLoop开始来学习服务端的 ...
- Qt5.5.1编译出来的程序出现libgcc_s_dw2-1.dll的解决方案
问题如图: 输入"myudp2016.exe 1 " 后出现 这是因为没有在系统环境变量path里加上相关路径,我们添加如下路径: 比如说WIN7系统-开始-计算机-右键-属性- ...
- PHP项目实现手机端和PC端的页面切换
目前访问页面的要切换成手机端和PC端,原理是通过对设备作出判断,显示不同的功能和页面. 如果手机端和PC端的功能结构不相同,一般会写两套系统,一套适用于PC端,一套适用于手机端. 如果功能相同,则只需 ...
- ubantu16.04+mxnet +opencv+cuda8.0 环境搭建
ubantu16.04+mxnet +opencv+cuda8.0 环境搭建 建议:环境搭建完成之后,不要更新系统(内核) 转载请注明出处: 微微苏荷 一 我的安装环境 系统:ubuntu16.04 ...
- android include进来的组件 调用其子元素
include标签包裹着一个可复用的布局: <include layout="@layout/footer_detail" android:id="@+id/foo ...
- 学习EXT.JS5时的重点载图
组件实例化的五种方式,最后一种不建议了 MVVM的图示,及controller的生存周期和MVC的不一样. VIEWCONTROLLER如何得到VIEW的实例呢,注意LOOKUPREFERENCE的使 ...
- oracle内存粒度
一,什么是内存粒度? When a database instance starts up, the amount of memory allocated is determined by the a ...
- Ubuntu(Linux系统)虚拟机工具vmtools详细说明
安装虚拟机工具vmtools大概步骤如下: 个人总结步骤: 第一步:点击虚拟机软件的vm工具栏选项,选择install vmware tools(安装VMware Tools) 第二步:桌面会出现一个 ...
- 修改cmd的字体为Consolas字体
Windows Registry Editor Version 5.00 [HKEY_CURRENT_USER\Console\%SystemRoot%_system32_cmd.exe] ...