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:
Matej Focko 2025-01-03 22:47:52 +01:00
parent a82b445053
commit 5c88e2bfe0
Signed by: mfocko
SSH key fingerprint: SHA256:icm0fIOSJUpy5+1x23sfr+hLtF9UhY8VpMC7H4WFJP8

View 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;
}
}