[leetcode] Best Time to Buy and Sell Stock II
来源:互联网 发布:淘宝联盟禁止微信 编辑:程序博客网 时间:2024/05/22 15:05
From : https://leetcode.com/problems/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).
class Solution {public: int maxProfit(vector<int>& prices) { int profit=0; for(int i=1,days=prices.size(); i<days; i++) { if(prices[i] > prices[i-1]) profit = profit+prices[i]-prices[i-1]; } return profit; }};
0 0
- [LeetCode]Best Time to Buy and Sell Stock II
- LeetCode Best Time to Buy and Sell Stock II
- Leetcode: Best Time to Buy and Sell Stock II
- [Leetcode] Best Time to Buy and Sell Stock II
- LeetCode : Best Time to Buy and Sell Stock II
- LeetCode Best Time to Buy and Sell Stock II
- [LeetCode] Best Time to Buy and Sell Stock II
- leetcode 61: Best Time to Buy and Sell Stock II
- [LeetCode] Best time to buy and sell a stock II
- 【leetcode】Best Time to Buy and Sell Stock II
- LeetCode - Best Time to Buy and Sell Stock II
- LeetCode之Best Time to Buy and Sell Stock II
- [LeetCode]Best Time to Buy and Sell Stock II
- [Leetcode]Best Time to Buy and Sell Stock II
- [leetcode]Best Time to Buy and Sell Stock II
- [LeetCode] Best Time to Buy and Sell Stock II
- LeetCode-Best Time to Buy and Sell Stock II
- [leetcode] Best Time to Buy and Sell Stock II
- hibernate事务管理
- java学习之旅03--JDK和JRE和JVM的区别,JDK的下载安装,环境变量配置,测试安装成功
- Spring MVC 拦截器
- CentOS搭建SVN服务器
- hdu 1157
- [leetcode] Best Time to Buy and Sell Stock II
- POJ2528 Mayor's poster 线段树 插入 查询 删除
- Word Search
- 深度优先搜索和广度优先搜索的比较与分析
- 用迭代法求 x=根号a。求平方根的迭代公式为:X(n+1)=(Xn+a/Xn) /2。
- XMemcachedClient实例的add方法和set方法区别
- 寻找最小生成树的kruskal算法的java实现
- Android数据库SQLite使用详解三 : 数据库的升级
- 形参默认参数