We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 95a8752 commit aa5498dCopy full SHA for aa5498d
problems/0122.买卖股票的最佳时机II.md
@@ -171,15 +171,15 @@ class Solution { // 动态规划
171
// 优化空间
172
class Solution {
173
public int maxProfit(int[] prices) {
174
- int[] dp=new int[2];
+ int[] dp = new int[2];
175
// 0表示持有,1表示卖出
176
- dp[0]=-prices[0];
177
- dp[1]=0;
178
- for(int i=1; i<=prices.length; i++){
+ dp[0] = -prices[0];
+ dp[1] = 0;
+ for(int i = 1; i <= prices.length; i++){
179
// 前一天持有; 或当天卖出然后买入
180
- dp[0]=Math.max(dp[0], dp[1]-prices[i-1]);
+ dp[0] = Math.max(dp[0], dp[1] - prices[i-1]);
181
// 前一天卖出; 或当天卖出,当天卖出,得先持有
182
- dp[1]=Math.max(dp[1], dp[0]+prices[i-1]);
+ dp[1] = Math.max(dp[1], dp[0] + prices[i-1]);
183
}
184
return dp[1];
185
0 commit comments