feat: 2025-10-28打卡
This commit is contained in:
23
122.best-time-to-buy-and-sell-stock-ii.java
Normal file
23
122.best-time-to-buy-and-sell-stock-ii.java
Normal file
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
* @lc app=leetcode id=122 lang=java
|
||||
*
|
||||
* [122] Best Time to Buy and Sell Stock II
|
||||
*/
|
||||
|
||||
// @lc code=start
|
||||
class Solution {
|
||||
public int maxProfit(int[] prices) {
|
||||
if(prices == null || prices.length <= 1) {
|
||||
return 0;
|
||||
}
|
||||
int total = 0;
|
||||
for(int i = 1; i<prices.length; i++) {
|
||||
if(prices[i] - prices[i-1] > 0) {
|
||||
total += prices[i] - prices[i-1];
|
||||
}
|
||||
}
|
||||
return total;
|
||||
}
|
||||
}
|
||||
// @lc code=end
|
||||
|
||||
Reference in New Issue
Block a user