最大公共字符串leetcode-leecode:代码

时间:2021-07-01 01:21:00
【文件属性】:
文件名称:最大公共字符串leetcode-leecode:代码
文件大小:161KB
文件格式:ZIP
更新时间:2021-07-01 01:21:00
系统开源 最大公共字符串leetcode typora-root-url images 每天复习一遍 思想 方法 121 /** * 121 https://leetcode-cn.com/problems/best-time-to-buy-and-sell-stock/ * * 思路: * 股票只能买卖一次 T+1 操作 * 最大利润 = 最高点 - 最低点 * 并且 最高点只能在 最低点的后面 * * */ public int maxProfit_1(int[] prices) { int maxProfit = 0; for (int i = 0; i < prices.length; i++) { for (int j = i+1; j < prices.length; j++) { if(prices[j] - prices[i] > maxProfit){ maxProfit = prices[j] - prices[i]; } } } return maxProfit; } public int maxProfit(int[] prices) { //找到一个最小值及它后面的最大

网友评论