LeetCode122:
给定一个数组prices,其中 prices[i]是一支给定股票第i天的价格。
设计一个算法来计算你所能获取的最大利润。你可以尽可能地完成更多的交易(多次买卖一支股票)。
注意:你不能同时参与多笔交易(你必须在再次购买前出售掉之前的股票)。
class Solution {public int maxProfit(int[] prices) {int profit = 0;int len = prices.length;for (int i = 1; i < len; i++) {int temp = prices[i] - prices[i - 1];if (temp > 0) {profit += temp;}}return profit;}}
