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 3107ba2 commit d7cadd6Copy full SHA for d7cadd6
problems/0122.买卖股票的最佳时机II.md
@@ -229,6 +229,21 @@ var maxProfit = function(prices) {
229
};
230
```
231
232
+C:
233
+```c
234
+int maxProfit(int* prices, int pricesSize){
235
+ int result = 0;
236
+ int i;
237
+ //从第二个元素开始遍历数组,与之前的元素进行比较
238
+ for(i = 1; i < pricesSize; ++i) {
239
+ //若该元素比前面元素大,则说明有利润。代表买入
240
+ if(prices[i] > prices[i-1])
241
+ result+= prices[i]-prices[i-1];
242
+ }
243
+ return result;
244
+}
245
+```
246
+
247
-----------------------
248
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
249
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
0 commit comments