当前位置:网站首页>Best time to buy and sell stock II
Best time to buy and sell stock II
2022-06-23 08:59:00 【ruochen】
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).
Sell as long as there is profit , It's the best solution .
public int maxProfit(int[] prices) {
int profit = 0;
for (int i = 1; i < prices.length; i++) {
if (prices[i - 1] < prices[i]) {
profit += prices[i] - prices[i - 1];
}
}
return profit;
}边栏推荐
- Flutter achieves the effect of selecting seats in the cinema!
- Quartz Crystal Drive Level Calculation
- Open source stealing malware mercurial found in the field for "educational purposes"
- 2022.6.22-----leetcode. five hundred and thirteen
- 简易学生管理
- 297. Serialize and Deserialize Binary Tree
- Utilisation du cookie du module de demande de noeud
- 125. Valid Palindrome
- USB peripheral driver - debug
- Kernel log debugging method
猜你喜欢

Object. Defineproperty() and data broker

Hongmeng reads the resource file

Geoserver添加mongoDB数据源

力扣之滑动窗口《循序渐进》(209.长度最小的子数组、904. 水果成篮)

297. Serialize and Deserialize Binary Tree

简易学生管理

Summary of communication mode and detailed explanation of I2C drive

Quartz Crystal Drive Level Calculation

The fourth online workshop review
![Paper reading [quovadis, action recognition? A new model and the dynamics dataset]](/img/3f/449cc91bfa66fcf26bc2cd405fb773.png)
Paper reading [quovadis, action recognition? A new model and the dynamics dataset]
随机推荐
Quartz Crystal Drive Level Calculation
523. Continuous Subarray Sum
TDesign update weekly report (the first week of January 2022)
Mysql 数据库入门总结
Leetcode topic analysis count primes
4、 Database design
3-progressbar and secondary cropping
JSP入门总结
173. Binary Search Tree Iterator
[advanced Android] kotlin notes
瞄准海外宠物市场,「Grasphand 」做了一款独立于手机的智能追踪产品 | 早期项目
Lighthouse cloud desktop experience
MQTT+Flink实现实时消息的订阅与发布
1-gradients, shadows, and text
636. Exclusive Time of Functions
[operating steps] how to set the easynvr hardware device to be powered on without automatic startup?
6月《中国数据库行业分析报告》发布!智能风起,列存更生
node request模塊cookie使用
Custom tag - JSP tag Foundation
Summary of communication mode and detailed explanation of I2C drive