中国建设银行网站太慢了,xin主题wordpress,今年最流行的装修风格,一个返利网站建设流程122.买卖股票的最佳时机II
为了获得最大利润#xff0c;我们可以将每一个局部峰值和局部谷值之间的差值累加起来。如果第 i 天的股票价格比第 i-1 天高#xff0c;则将这两天的股票进行买卖#xff0c;即累加差值 (prices[i] - prices[i-1])#xff0c;否则不进行交易。
… 122.买卖股票的最佳时机II
为了获得最大利润我们可以将每一个局部峰值和局部谷值之间的差值累加起来。如果第 i 天的股票价格比第 i-1 天高则将这两天的股票进行买卖即累加差值 (prices[i] - prices[i-1])否则不进行交易。
class Solution {
public:int maxProfit(vectorint prices) {int maxProfit 0;for (int i 1; i prices.size(); i) {if (prices[i] prices[i - 1]) {maxProfit prices[i] - prices[i - 1];}}return maxProfit;}
};55.跳跃游戏
class Solution {
public:bool canJump(vectorint nums) {int maxReach 0;int n nums.size();for (int i 0; i n; i) {if (maxReach i) return false; // 如果当前位置无法到达则返回falsemaxReach max(maxReach, i nums[i]); // 更新当前能够到达的最远位置if (maxReach n - 1) return true; // 如果当前位置能够到达最后一个位置则返回true}return false; // 遍历结束仍未到达最后一个位置返回false}