Best Time to Buy and Sell Stock II 2021-06-01 20:21

Problem Description

public static int maxProfit(int[] prices) {
    int res = 0;
    for (int i = 1; i < prices.length; i++) {
        if (prices  [i - 1] < prices[i]) {
            res = prices[i] - prices[i - 1] + res;
        }
    }
    return res;
}
Runtime Memory
1 ms 41 MB

henryxi leetcode list

EOF