122. Best Time to Buy and Sell Stock II

来源:互联网 发布:linux存储服务器有哪些 编辑:程序博客网 时间:2024/05/16 04:34

解法一:

public class Solution {    public int maxProfit(int[] prices) {        if (prices.length<2)     return 0; int sumProfit = 0,startIndex = 0; for (int i = 1; i < prices.length; i++) {if (prices[i]>prices[i-1]) {sumProfit = sumProfit+prices[i]-prices[i-1];}}     return sumProfit;    }}

0 0
原创粉丝点击