leetcode 122-Best Time to Buy and Sell Stock II
来源:互联网 发布:windows phone微信 编辑:程序博客网 时间:2024/06/06 02:03
难度:easy
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).
审题:此题是list的第i个元素表示当天的股票价格,此题中,股票可以多次买出买进,可以当天买进再卖出,但是必须保证盈利。1.手中只能是一只股票,必须先买入再卖出,卖出以后方能再买入。
2.只要后一位比前一位小,price[i+1]>price[i],即可实现买入再卖出
3. 所有的买入和卖出差就是总利润。
思路:用while或者for循环皆可实现。
阅读全文
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
- 网络检测的简单方法
- python学习总结---字典
- convert-sorted-array-to-binary-search-tree
- easyui的tree 控件设置checkbox单选设置
- 数据结构实验之图论一:基于邻接矩阵的广度优先搜索遍历
- leetcode 122-Best Time to Buy and Sell Stock II
- 搭建nginx rtmp流媒体服务器(超详细)
- STL应用-——懒省事的小明
- 文章标题
- vscode: Visual Studio Code 常用快捷键
- 实现容器的底层技术
- Linux下切换python2和python3
- C++ 结构体可以直接赋值
- Python基础4