java: add «122. Best Time to Buy and Sell Stock II»
URL: https://leetcode.com/problems/best-time-to-buy-and-sell-stock-ii/ Signed-off-by: Matej Focko <me@mfocko.xyz>
This commit is contained in:
parent
a82b445053
commit
5c88e2bfe0
1 changed files with 13 additions and 0 deletions
13
java/best-time-to-buy-and-sell-stock-ii.java
Normal file
13
java/best-time-to-buy-and-sell-stock-ii.java
Normal file
|
@ -0,0 +1,13 @@
|
|||
class Solution {
|
||||
public int maxProfit(int[] prices) {
|
||||
var profit = 0;
|
||||
|
||||
for (var i = 1; i < prices.length; ++i) {
|
||||
if (prices[i] > prices[i - 1]) {
|
||||
profit += prices[i] - prices[i - 1];
|
||||
}
|
||||
}
|
||||
|
||||
return profit;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue