生活随笔
收集整理的這篇文章主要介紹了
122 买卖股票二
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
122 Best Time to Buy and Sell Stock II
文章目錄
- 122 Best Time to Buy and Sell Stock II
class Solution {public int maxProfit(int[] prices
) {if(prices
.length
==0 ) return 0;int max
=0;for(int i
=1;i
<prices
.length
;i
++){if(prices
[i
] >prices
[i
-1]){max
+=prices
[i
] -prices
[i
-1];}}return max
;}
}
總結(jié)
以上是生活随笔為你收集整理的122 买卖股票二的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。