121.Best Time to Buy and Sell Stock
class Solution {
public:int maxProfit(vector<int>& prices) {int n = prices.size();if (n==0){return 0;}int res = 0;int mmin = prices[0];for (int i=1;i<n;i++){res = max(res,prices[i]-mmin);mmin = min(mmin,prices[i]);}return res;}
};
转载于:https://www.cnblogs.com/smallredness/p/10677152.html
121.Best Time to Buy and Sell Stock相关推荐
- 【贪心 和 DP + 卖股票】LeetCode 121. Best Time to Buy and Sell Stock
LeetCode 121. Best Time to Buy and Sell Stock Solution1:我的答案 动态规划和贪心不要区分的那么明显嘛~~~ class Solution { p ...
- LeetCode 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 ...
- LeetCode 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 w ...
- leetcode python3 简单题121. Best Time to Buy and Sell Stock
1.编辑器 我使用的是win10+vscode+leetcode+python3 环境配置参见我的博客: 链接 2.第一百二十一题 (1)题目 英文: Say you have an array fo ...
- Leetcode——121. Best Time to Buy and Sell Stock
题目原址 https://leetcode.com/problems/best-time-to-buy-and-sell-stock/description/ 题目描述 Say you have an ...
- LeetCode 121 Best Time to Buy and Sell Stock(股票买入卖出的最佳时间)
翻译 话说你有一个数组,其中第i个元素表示在第i天的股票价格.如果你被只被允许最多一次交易(例如,买入然后卖出一个股票),设计一个算法并找出最大利润. 原文 Say you have an array ...
- leetcode 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 w ...
- 121. Best Time to Buy and Sell Stock买卖股票的最佳时机
You are given an array prices where prices[i] is the price of a given stock on the ith day. 给定一个数组 p ...
- 121 Best Time to Buy and Sell Stock
输入:一个数组prices,prices[i]表示第i天股票的价格. 输出:买卖股票的最大收益. 规则:只允许最多买一次,最多卖一次股票.如果觉得价格不合适,可以不买卖. 分析1:最先想到的是暴力搜索 ...
- 121. Best Time to Buy and Sell Stock
一.题目 1.审题 2.分析 给出一个数组,让你先已 val1 买入,再 以 val2 卖出,求获得的利润最大是多少. 二.解答 1.思路: 方法一. 用遍历 min 记录到当前位置的最小值: max ...
最新文章
- java 数组的应用(一维)
- Web 插件 之 ECharts 实现中国地图数据的简单展示实现
- java 图片转pdf_在Java语言中将图像转换为PDF?Spire.PDF for Java轻松搞定!
- struct termios 结构体详解
- 11x 程序员专属 TapTap 代码编辑器主题
- 解决win10分辨率过高导致某些软件显示小的办法
- 4个C++算法数学模板(备战蓝桥杯)
- 腾达n318虚拟服务器,腾达N318无线路由器的设置教程
- 《车载图像采集仿真应用指南》之基于图像采集的座舱测试
- 养生秘方,专治各种小毛病,千万别弄丢了!
- Quora如何在快速开发中保持高品质代码
- 腾讯云数据库 TencentDB for MariaDB快速入门和常见问题
- dg打开软件Android,DG 文件扩展名: 它是什么以及如何打开它?
- 交叉熵损失函数详解推导
- VS2015 C++/CLR
- 2022年最新面试JVM面试追魂夺命17问,教科书级回答
- 【求助】关于.NET(C#)调用斑马打印机(ZDesigner GK888t (EPL))换页时退纸的问题
- ANSYS软件之问题1——调出HFSS模块
- linux驱动学习笔记(九)SPI
- linux 恶意软件检测,两款针对Linux系统Rootkit和恶意软件的有用检测工具
热门文章
- mysql+索引+rebuild_(solr系列:五) solr定时实时重建索引和增量更新
- oracle lock 1,Oracle試用 DBMS_LOCK.sleep(1);權限問題
- pymysql ︱mysql的基本操作与dbutils+PooledDB使用
- 纯前端控件集 WijmoJS 2018V2发布,提供可视化设计器,在React、Vue和Angular中的更易用...
- MacOS下安装Grafana、InfluxData、telegraf
- angular2系列之动画-路由转场动画
- Docker mysql
- Thrift原理与使用实例
- 一个简简单单检测http服务状态的脚本
- Matlab与Access数据库的连接