Leecode数据结构刷题记录第五天:121. 买卖股票的最佳时机
①:暴力法
public class Solution { public int MaxProfit(int[] prices) { int finalProfit = 0; for (int i = 0; i < prices.Length-1; i++) { for (int j = i; j < prices.Length; j++) { int profit = prices[j] - prices[i]; if (profit > finalProfit) { finalProfit = profit; } } } return finalProfit; } }
②:动态规划(等我学会了就来写)