当前位置:网站首页>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
边栏推荐
- Small record of thinking
- 02 specific implementation of LS command
- Leader: who uses redis expired monitoring to close orders and get out of here!
- hbuildx中夜神模拟器的配置以及热更新
- dried food! Generation of rare samples based on GaN
- Flink learning 6: programming model
- RHCSA 06 - suid, sgid, sticky bit(待补充)
- Interpretation of leveldb source code skiplist
- Architecture training graduation design + summary
- Two commonly used graphics can easily realize data display
猜你喜欢
随机推荐
Ppt tutorial, how to save a presentation as a PDF file in PowerPoint?
仿《游戏鸟》源码 手游发号评测开服开测合集专区游戏下载网站模板
Restore the subtlety of window position
指针数组和数组指针
Unity 绘制弹球和台球的运动轨迹
旭化成首次参展第五届中国国际进口博览会(5th CIIE)
(pointeur) Écrivez - vous une fonction qui compare la taille de la chaîne et fonctionne comme strcmp.
透过JVM-SANDBOX源码,了解字节码增强技术原理
浅谈一篇优质的小红书文案需要具备什么
Parameterization of controls in katalon
One click compilation and deployment of MySQL
C language bidirectional linked list first edition
西部数据绿盘、蓝盘、黑盘、红盘和紫盘有什么区别
资深开发人员告诉你,怎样编写出优秀的代码?
Modstartblog modern personal blog system v5.2.0 source code download
Operation of ES6
(指针)编写函数void fun(int x,int *pp,int *n)
【微服务|openfeign】@FeignClient详解
EIG在智利推出可再生能源平台Grupo Cerro
RHCSA 07 - 用户与群组管理