leetcode121】的更多相关文章

题目: Say you have an array for which the ith element is the price of a given stock on day i. If you were only permitted to complete at most one transaction (ie, buy one and sell one share of the stock), design an algorithm to find the maximum profit.…
#121   Best Time to Buy and Sell Stock Say you have an array for which the ith element is the price of a given stock on day i. If you were only permitted to complete at most one transaction (ie, buy one and sell one share of the stock), design an alg…
Say you have an array for which the ith element is the price of a given stock on day i. If you were only permitted to complete at most one transaction (i.e., buy one and sell one share of the stock), design an algorithm to find the maximum profit. No…
public class Solution { public int MaxProfit(int[] prices) { //寻找最优极值点(包括2个端点) ) { ; } ) { ] - prices[] > ? prices[] - prices[] : ; } else//至少3个点 { //先对原始数据进行压缩 var list = new List<int>(); ; i < prices.Length - ; i++) { ]) { list.Add(prices[i]…
给定一个数组,它的第 i 个元素是一支给定股票第 i 天的价格. 如果你最多只允许完成一笔交易(即买入和卖出一支股票),设计一个算法来计算你所能获取的最大利润. 注意你不能在买入股票前卖出股票. 示例 1: 输入: [7,1,5,3,6,4] 输出: 5 解释: 在第 2 天(股票价格 = 1)的时候买入,在第 5 天(股票价格 = 6)的时候卖出,最大利润 = 6-1 = 5 . 注意利润不能是 7-1 = 6, 因为卖出价格需要大于买入价格. 示例 2: 输入: [7,6,4,3,1] 输出…
[题目] Say you have an array for which the ith element is the price of a given stock on day i. If you were only permitted to complete at most one transaction (i.e., buy one and sell one share of the stock), design an algorithm to find the maximum profi…
Say you have an array for which the ith element is the price of a given stock on day i. If you were only permitted to complete at most one transaction (i.e., buy one and sell one share of the stock), design an algorithm to find the maximum profit. No…
leetcode121 Best Time to Buy and Sell Stock 说白了找到最大的两组数之差即可 class Solution { public: int maxProfit(vector<int>& prices) { ; ; i < prices.size(); i++){ ; j < prices.size(); j++){ m = max(m, prices[j] - prices[i]); } } return m; } }; leetcod…
Your are given an array of integers prices, for which the i-th element is the price of a given stock on day i; and a non-negative integer feerepresenting a transaction fee. You may complete as many transactions as you like, but you need to pay the tr…
Say you have an array for which the ith element is the price of a given stock on day i. Design an algorithm to find the maximum profit. You may complete at most ktransactions. Note:You may not engage in multiple transactions at the same time (ie, you…