博客
关于我
Leetcode 121. 买卖股票的最佳时机(DAY 26) ---- 动态规划学习期
阅读量:207 次
发布时间:2019-02-28

本文共 637 字,大约阅读时间需要 2 分钟。

原题题目

在这里插入图片描述



代码实现(首刷自解) 一遍遍历 但为什么效率极低

int maxProfit(int* prices, int pricesSize){       int i,min = INT_MAX,max = -1,profit = -1;    for(i=0;i
max) { max = prices[i]; if(max - min > profit) profit = max - min; } } } return profit;}

代码实现(二刷C++ 整理股票博客)

class Solution {   public:    int maxProfit(vector
& prices) { int size = prices.size(),minbuy = prices[0],maxsold = 0; for(const auto& num:prices) { maxsold = max(maxsold,num-minbuy); minbuy = min(minbuy,num); } return maxsold; }};

转载地址:http://shji.baihongyu.com/

你可能感兴趣的文章
NetScaler的常用配置
查看>>
netsh advfirewall
查看>>
NETSH WINSOCK RESET这条命令的含义和作用?
查看>>
netstat kill
查看>>
netstat命令用法详解
查看>>
Netstat端口占用情况
查看>>
Netty 4的内存管理:sun.misc.Unsafe
查看>>
Netty channelRegistered\ChannelActive---源码分析
查看>>
Netty NIO transport && OIO transport
查看>>
netty php,netty
查看>>
Netty WebSocket客户端
查看>>
netty 主要组件+黏包半包+rpc框架+源码透析
查看>>
Vue过渡 & 动画---vue工作笔记0014
查看>>
Netty 异步任务调度与异步线程池
查看>>
Netty 的 Handler 链调用机制
查看>>
Netty 编解码器和 Handler 调用机制
查看>>
Netty 编解码器详解
查看>>
Netty 解决TCP粘包/半包使用
查看>>