当前位置:网站首页>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
边栏推荐
- Redis cluster uses Lua script. Lua script can also be used for different slots
- 【微服务|openfeign】@FeignClient详解
- 网络 - VXLAN
- NFT新的契机,多媒体NFT聚合平台OKALEIDO即将上线
- The interactive solution of JS and app in the H5 page embedded in app (parameters can be transferred and callbacks can be made)
- 沃博联结束战略评估,决定保留表现优异的博姿业务
- Apple CMS imitation watermelon video atmospheric response video template source code
- 一位毕业生的自我分享
- Small record of thinking
- Touch and take you to implement an EventEmitter
猜你喜欢
How to telecommute more efficiently | community essay solicitation
Apple CMS imitation watermelon video atmospheric response video template source code
【愚公系列】2022年7月 Go教学课程 002-Go语言环境安装
5张图告诉你:同样是职场人,差距怎么这么大?
量子力学习题
R语言dplyr中的Select函数变量列名
Keysight N9320B射频频谱分析仪解决轮胎压力监测方案
Redis:哈希hash类型数据操作命令
Ppt tutorial, how to save a presentation as a PDF file in PowerPoint?
指针数组和数组指针
随机推荐
Emlog用户注册插件 价值80元
2021 RSC | Drug–target affinity prediction using graph neural network and contact maps
hbuildx中夜神模拟器的配置以及热更新
DP83848+网线热拔插
Redis:哈希hash类型数据操作命令
Confession code collection, who says program apes don't understand romance
毕业设计项目
Perf simple process for multithreaded profile
01 QEMU starts the compiled image vfs: unable to mount root FS on unknown block (0,0)
(指针)自己写一个比较字符串大小的函数,功能与strcmp类似。
VIM add interval annotation correctly
Understand the principle of bytecode enhancement technology through the jvm-sandbox source code
EIG在智利推出可再生能源平台Grupo Cerro
Boutique website navigation theme whole station source code WordPress template adaptive mobile terminal
Use NRM and NVM to manage your NPM source and node versions
“找工作不要太在意工资”,这是我听过最大的谎言
How to telecommute more efficiently | community essay solicitation
西部数据绿盘、蓝盘、黑盘、红盘和紫盘有什么区别
Leetcode skimming: binary tree 09 (minimum depth of binary tree)
线程常用的方法