当前位置:网站首页>leetcode 121 Best Time to Buy and Sell Stock 买卖股票的最佳时机(简单)
leetcode 121 Best Time to Buy and Sell Stock 买卖股票的最佳时机(简单)
2022-07-04 03:52:00 【InfoQ】
一、题目大意
- 1 <= prices.length <= 105
- 0 <= prices[i] <= 104
二、解题思路
三、解题方法
3.1 Java实现
public class Solution {
public int maxProfit(int[] prices) {
// 记录i位置之前所有价格中的最低价格
int buy = prices[0];
// 当前最大利润
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;
}
}
四、总结小记
- 2022/7/3 接下来几天都有雨
边栏推荐
- leetcode刷题:二叉树04(二叉树的层序遍历)
- JS实现文字滚动 跑马灯效果
- 96% of the collected traffic is prevented by bubble mart of cloud hosting
- I Build a simple microservice project
- 深度优先搜索简要讲解(附带基础题)
- Leetcode skimming: binary tree 04 (sequence traversal of binary tree)
- Myslq delete followed by limit
- Leetcode brush questions: binary tree 05 (flip binary tree)
- Two commonly used graphics can easily realize data display
- 【华为云IoT】读书笔记之《万物互联:物联网核心技术与安全》第3章(上)
猜你喜欢

Flink学习7:应用程序结构

Flink learning 6: programming model

My opinion on how to effectively telecommute | community essay solicitation

【微服务|openfeign】@FeignClient详解

Leetcode skimming: binary tree 08 (maximum depth of n-ary tree)

Leetcode skimming: binary tree 09 (minimum depth of binary tree)

What does software testing do? Find defects and improve the quality of software

I Build a simple microservice project

Leetcode brush question: binary tree 06 (symmetric binary tree)

三菱M70宏变量读取三菱M80公共变量采集三菱CNC变量读取采集三菱CNC远程刀补三菱机床在线刀补三菱数控在线测量
随机推荐
The new data center helps speed up the construction of a digital economy with data as a key element
深度优先搜索简要讲解(附带基础题)
【webrtc】m98 ninja 构建和编译指令
(指针)编写函数void fun(int x,int *pp,int *n)
Leetcode brush questions: binary tree 05 (flip binary tree)
dried food! Generation of rare samples based on GaN
Myslq delete followed by limit
Leetcode skimming: binary tree 07 (maximum depth of binary tree)
(指针)自己写一个比较字符串大小的函数,功能与strcmp类似。
ctf-pikachu-XSS
[Yugong series] go teaching course 002 go language environment installation in July 2022
RHCSA 04 - 进程管理
The three-year revenue is 3.531 billion, and this Jiangxi old watch is going to IPO
CesiumJS 2022^ 源码解读[0] - 文章目录与源码工程结构
[book club issue 13] multimedia processing tool ffmpeg tool set
Brief explanation of depth first search (with basic questions)
Rhcsa-- day one
vim正确加区间注释
Flink learning 8: data consistency
Redis cluster uses Lua script. Lua script can also be used for different slots