当前位置:网站首页>Leetcode 121 best time to buy and sell stock (simple)
Leetcode 121 best time to buy and sell stock (simple)
2022-07-04 04:26:00 【InfoQ】
One 、 The main idea of the topic
- 1 <= prices.length <= 105
- 0 <= prices[i] <= 104
Two 、 Their thinking
3、 ... and 、 How to solve the problem
3.1 Java Realization
public class Solution {
public int maxProfit(int[] prices) {
// Record i The lowest of all prices before the location
int buy = prices[0];
// The biggest profit at the moment
int profit = 0;
for (int i = 1; i < prices.length; i++) {
buy = Math.min(buy, prices[i]);
profit = Math.max(profit, prices[i] - buy);
}
return profit;
}
}
Four 、 Summary notes
- 2022/7/3 It will rain for the next few days
边栏推荐
- C语言单向链表练习
- Leetcode skimming: binary tree 09 (minimum depth of binary tree)
- RPC技术
- RHCSA 03 - 文件的基础权限
- MIN_RTO 对话
- Unity draws the trajectory of pinball and billiards
- How to add custom API objects in kubernetes (1)
- Apple CMS imitation watermelon video atmospheric response video template source code
- Ppt tutorial, how to save a presentation as a PDF file in PowerPoint?
- Leader: who uses redis expired monitoring to close orders and get out of here!
猜你喜欢

Imitation of "game bird" source code, mobile game issue evaluation, open service, open test collection, game download website template

什么是上下文?

Flink学习7:应用程序结构

Virtual commodity account trading platform source code_ Support personal QR code collection

dried food! Generation of rare samples based on GaN

精品网址导航主题整站源码 wordpress模板 自适应手机端

Emlog user registration plug-in is worth 80 yuan

Flink learning 8: data consistency

微信公众号无限回调授权系统源码

Flink学习8:数据的一致性
随机推荐
leetcode刷题:二叉树04(二叉树的层序遍历)
Touch and take you to implement an EventEmitter
分布式系统:what、why、how
tdk-lambda电源主要应用
Confession code collection, who says program apes don't understand romance
【微服务|openfeign】使用openfeign远程调用文件上传接口
VIM mapping command
程序员远程办公喜忧参半| 社区征文
(指针)编写函数void fun(int x,int *pp,int *n)
I.MX6U-ALPHA开发板(C语言版本LED驱动实验)
Unity资源路径
2021 RSC | Drug–target affinity prediction using graph neural network and contact maps
I.MX6U-ALPHA开发板(模仿STM32驱动开发实验)
什么是上下文?
Tcp- simple understanding of three handshakes and four waves
毕业设计项目
2021 RSC | Drug–target affinity prediction using graph neural network and contact maps
多位科技公司创始人向Entrepreneur First提供高达1.58亿美元的C轮融资,协助其投资下一代全球创新者
leetcode刷题:二叉树08(N叉树的最大深度)
RHCSA 08 - automount配置