We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
典型的dp问题,状态转移方程式为 第i天的最大收益 = max(第i - 1 天的收益,当天的价格 - 之前最小的价格)
/** * @param {number[]} prices * @return {number} */ var maxProfit = function(prices) { if(prices.length === 0) { return 0; } let dp = Array(prices.length).fill(0); let sum = prices[0]; for(let i = 1;i<prices.length;i++) { dp[i] = Math.max(prices[i] - sum,dp[i -1]); if(sum > prices[i]) { sum = prices[i]; } } return dp.sort((a,b)=>b-a)[0]; };
The text was updated successfully, but these errors were encountered:
No branches or pull requests
典型的dp问题,状态转移方程式为 第i天的最大收益 = max(第i - 1 天的收益,当天的价格 - 之前最小的价格)
The text was updated successfully, but these errors were encountered: