当前位置:网站首页>LeetCode每日两题02:买股票的最佳时机 (均1200道)
LeetCode每日两题02:买股票的最佳时机 (均1200道)
2022-08-07 15:13:00 【那人独钓寒江雪.】

解题思路:
class Solution {
public int maxProfit(int[] prices) {
int total = 0;
for (int i = 0; i < prices.length - 1; i++) {
//原数组中如果后一个减去前一个是正数,说明是上涨的,
//我们就要累加,否则就不累加
total += Math.max(prices[i + 1] - prices[i], 0);
}
return total;
}
}
边栏推荐
- Summary of the open surface
- Hash table | 1. The sum of two numbers, 454. The addition of four numbers | The most suitable `dictionary key-value` | leecode brush the notes
- 基于FPGA的VGA显示彩条、字符、图片
- 浏览器工作原理与实践学习笔记(一)宏观视角下的浏览器
- 服务器管理面板aaPanel使用中的一些问题汇总
- 使用通达信炒股,资金能保证安全吗?
- Expert C Programming Chapter 8 Why Programmers Can't Tell the Difference Between Halloween and Christmas 8.3 Types Change While Waiting
- C语言文件读写操作/标准IO
- 测开面经汇总
- 数据文件未用正确方法删除后的解决方案
猜你喜欢
![Two-day summary ([20][21])](/img/cd/2d925b9d77c77e72e4ff2db29a6cdf.png)
Two-day summary ([20][21])

MySQL的UPDATE及SELECT...FOR UPDATE语句关于锁的一些简单验证

C Expert Programming Chapter 8 Why Programmers Can't Tell the Difference Between Halloween and Christmas 8.7 Implementing Finite State Machines in C

Lianshengde W801 series 1-flash save data routine: save wifi distribution network information

LeetCode Hot Question HOT 100 (7. The container that holds the most water)

小技巧——postman生成在线文档

The ADC external RC circuit resistance and capacitance selection calculation method

LeetCode 热题 HOT 100(10.删除链表的倒数第 N 个结点)

哈希表 | 三数之和、四数之和 | 用`双指针法`最合适 | leecode刷题笔记

Chapter 14 主题模型
随机推荐
实用代码使用浏览器添加书签方式来一键获取网页所需内容链接技巧分享
[Principle of Database System] Chapter 4 Advanced Database Model: E/R Model and Its Design Rules and Constraints
Programming Experts in C Chapter 8 Why Programmers Can't Tell the Difference Between Halloween and Christmas 8.9 How and Why Casting
LeetCode每日一题(911. Online Election)
SWM32系列教程7-I2C及其应用
小技巧——postman生成在线文档
【通信原理】第三章 -- 随机过程[补充]
现在网上开户安全?想知道股票开账户如何优惠开户?
一、Flink 处理IOT数据
LeetCode hot topic HOT 100 (10. Delete the Nth node from the bottom of the linked list)
微信小程序——小程序中计算属性的使用
Expert C Programming Chapter 8 Why Programmers Can't Tell the Difference Between Halloween and Christmas 8.2 Building Graphics from Bit Patterns
服务器管理面板aaPanel使用中的一些问题汇总
RTT学习笔记9-IO设备模型
Summary of the open surface
初始百度地图API
labelme安装
响应状态码
联盛德W801系列4-MQTT使用
微信小程序——video视频全屏展示