leetcode121专题

【代码随想录算法训练营第四十九天 | LeetCode121. 买卖股票的最佳时机、122.买卖股票的最佳时机II 】

代码随想录算法训练营第四十九天 | LeetCode121. 买卖股票的最佳时机、122.买卖股票的最佳时机II 一、121. 买卖股票的最佳时机 解题代码C++: class Solution {public:int maxProfit(vector<int>& prices) {int low = INT_MAX;int result = 0;for (int i = 0; i <

leetcode121~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), d

leetcode121,122(卖出股票的最佳时机)

给定一个数组,它的第 i 个元素是一支给定股票第 i 天的价格。     设计一个算法来计算你所能获取的最大利润。你可以尽可能地完成更多的交易(多次买卖一支股票)。  思路。只需要前一天比后一天小就可以前一天卖出,买进,后一天再卖出,计算 public static int maxProfit1(int[] prices) {int sum = 0;for(int i=1;i<prices.

LeetCode121 Best Time to Buy and Sell Stock

题目要求: 121. Best Time to Buy and Sell Stock QuestionEditorial Solution My Submissions Total Accepted: 139457Total Submissions: 364702Difficulty: EasyContributors: AdminSay you have an array for w