当前位置:网站首页>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
边栏推荐
- 5张图告诉你:同样是职场人,差距怎么这么大?
- y55.第三章 Kubernetes从入门到精通 -- HPA控制器及metrics-server(二八)
- C语言双向链表初版
- Idea modify body color
- Modstartblog modern personal blog system v5.2.0 source code download
- Leetcode skimming: binary tree 04 (sequence traversal of binary tree)
- leetcode刷题:二叉树04(二叉树的层序遍历)
- Flink learning 8: data consistency
- I.MX6U-ALPHA开发板(C语言版本LED驱动实验)
- 2021 RSC | Drug–target affinity prediction using graph neural network and contact maps
猜你喜欢

Flink学习7:应用程序结构

博朗与Virgil Abloh于2021年为纪念博朗品牌100周年而联合打造的“功能性艺术”将在博物馆展出Abloh作品期间首次亮相

02 specific implementation of LS command

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

Keysight N9320B射频频谱分析仪解决轮胎压力监测方案

仿《游戏鸟》源码 手游发号评测开服开测合集专区游戏下载网站模板

DP83848+网线热拔插

Flink学习6:编程模型

十字路口通行优先权,十字路口通行规则图解

干货!基于GAN的稀有样本生成
随机推荐
Small record of thinking
How to add custom API objects in kubernetes (1)
C language bidirectional linked list first edition
Redis:哈希hash类型数据操作命令
毕业设计项目
Unity 绘制弹球和台球的运动轨迹
Unity draws the trajectory of pinball and billiards
The difference between bagging and boosting in machine learning
VIM add interval annotation correctly
Three years of graduation, half a year of distance | community essay solicitation
How to add custom API objects in kubernetes (1)
Unity Resource path
01 QEMU starts the compiled image vfs: unable to mount root FS on unknown block (0,0)
NFT新的契机,多媒体NFT聚合平台OKALEIDO即将上线
leetcode刷题:二叉树04(二叉树的层序遍历)
Flink learning 8: data consistency
leetcode刷题:二叉树08(N叉树的最大深度)
leetcode 121 Best Time to Buy and Sell Stock 买卖股票的最佳时机(简单)
虚拟商品帐号交易平台源码_支持个人二维码收款
Virtual commodity account trading platform source code_ Support personal QR code collection