LeetCode 122 Best Time to Buy and Sell Stock II
来源:互联网 发布:eve捏脸数据男 编辑:程序博客网 时间:2024/06/05 02:27
告诉你每天股票的价格,你可以选择买入或者卖出1支股票,问最多赚多少?把第二天比第一天大的加起来就好了。这道题虽然看起来水,不过蕴含着非常大的哲理
class Solution {public: int maxProfit(vector<int>& prices) { int ans = 0; for (int i = 1; i < prices.size(); i++) { int t = prices[i] - prices[i - 1]; if (t > 0) ans += t; } return ans; }};
0 0
- LeetCode 122: Best Time to Buy and Sell Stock II
- LeetCode 122 Best Time to Buy and Sell Stock II
- LeetCode 122 Best Time to Buy and Sell Stock II
- LeetCode: Best Time to Buy and Sell Stock II [122]
- [leetcode 122] Best Time to Buy and Sell Stock II
- leetcode-122 Best Time to Buy and Sell Stock II
- leetcode || 122、Best Time to Buy and Sell Stock II
- LeetCode 122: Best Time to Buy and Sell Stock II
- Leetcode# 122 Best Time to Buy and Sell Stock II
- leetcode 122: Best Time to Buy and Sell Stock II
- leetCode #122 Best Time to Buy and Sell Stock II
- leetcode: (122) Best Time to Buy and Sell Stock II
- 122 Best Time to Buy and Sell Stock II [Leetcode]
- LeetCode 122: Best Time to Buy and Sell Stock II
- LeetCode 122 Best Time to Buy and Sell Stock II
- 【LEETCODE】122-Best Time to Buy and Sell Stock II
- [leetcode 122] Best Time to Buy and Sell Stock II
- 【leetcode】【122】Best Time to Buy and Sell Stock II
- UVA 11732 "strcmp()" Anyone?
- BestCoder Round #85
- HDU 5755 高斯消元
- 杂记----安全感
- gdb调试core文件2
- LeetCode 122 Best Time to Buy and Sell Stock II
- 把数组拼接成一个字符串 */
- C++编程之内存管理(再谈)
- 《Windows环境下32位汇编语言程序设计(第2版)》-chapter10
- 把字符串反转
- 个人职业--跌跌撞撞的成长
- XML 和 HTML
- 判断一个字符串是否是对称字符串
- getElementById(), getElementsByName()和 getElementsByTagName() 详解