当前位置:网站首页>309. the best time to buy and sell stocks includes the freezing period
309. the best time to buy and sell stocks includes the freezing period
2022-06-23 07:08:00 【Graduation_ Design】
Preface
C++ It's a high-level programming language , from C Language expansion and upgrading , As early as 1979 By Benjani · Strauss LUP is AT&T Developed by Bell studio .
C++ Both can be carried out C Process programming of language , It can also be used for object-based programming characterized by abstract data types , It can also carry out object-oriented programming characterized by inheritance and polymorphism .C++ Good at object-oriented programming at the same time , You can also do process based programming .
C++ Have the practical characteristics of computer operation , At the same time, it is also committed to improving the programming quality of large-scale programs and the problem description ability of programming languages .
Java Is an object-oriented programming language , Not only absorbed C++ The advantages of language , It's abandoned C++ The incomprehensible inheritance in 、 Concepts such as pointer , therefore Java Language has two characteristics: powerful and easy to use .Java As the representative of static object-oriented programming language , Excellent implementation of object-oriented theory , Allow programmers to do complex programming in an elegant way of thinking .
Java It's simple 、 object-oriented 、 Distributed 、 Robustness, 、 Security 、 Platform independence and portability 、 Multithreading 、 Dynamic and so on .Java Can write desktop applications 、Web Applications 、 Distributed system and embedded system applications, etc .
Python By Guido of the Dutch Society for mathematical and computer science research · Van rosum On 1990 It was designed in the early 's , As a course called ABC A substitute for language .Python Provides efficient advanced data structure , It's also a simple and effective way of object-oriented programming .Python Syntax and dynamic types , And the nature of interpretative language , Make it a programming language for scripting and rapid application development on most platforms , With the continuous update of the version and the addition of new language features , Gradually used for independent 、 Development of large projects .
Python The interpreter is easy to extend , have access to C Language or C++( Or something else can be done through C Calling language ) Expand new functions and data types .Python It can also be used as an extensible programming language in customizable software .Python Rich library of standards , Provides source code or machine code for each major system platform .
2021 year 10 month , Compiler for language popularity index Tiobe take Python Crowned the most popular programming language ,20 Put it in... For the first time in years Java、C and JavaScript above .
describe
Given an array of integers prices, Among them the first prices[i] It means the first one i Day's share price .
Design an algorithm to calculate the maximum profit . Under the following constraints , You can do as many deals as you can ( Buy and sell a stock many times ):
After sale of shares , You can't buy shares the next day ( That is, the freezing period is 1 God ).
Be careful : You can't participate in multiple transactions at the same time ( You have to sell the stock before you buy it again ).
Example 1:
Input : prices = [1,2,3,0,2]
Output : 3
explain : The corresponding transaction status is : [ purchase , sell , Freezing period , purchase , sell ]
Example 2:
Input : prices = [1]
Output : 0
class Solution {
public int maxProfit(int[] prices) {
if (prices.length == 0) {
return 0;
}
int n = prices.length;
// f[i][0]: The biggest return on the stock you hold
// f[i][1]: I don't have stock in my hand , And it's in the middle of the freezing period
// f[i][2]: I don't have stock in my hand , And the cumulative maximum return not in the freezing period
int[][] f = new int[n][3];
f[0][0] = -prices[0];
for (int i = 1; i < n; ++i) {
f[i][0] = Math.max(f[i - 1][0], f[i - 1][2] - prices[i]);
f[i][1] = f[i - 1][0] + prices[i];
f[i][2] = Math.max(f[i - 1][1], f[i - 1][2]);
}
return Math.max(f[n - 1][1], f[n - 1][2]);
}
}
边栏推荐
- Using fuser to view file usage
- SSM整合
- 别找了诸位 【十二款超级好用的谷歌插件都在这】(确定不来看看?)
- 1161 Merging Linked Lists
- MySQL重做日志 redo log
- 关于#sql#的问题:有没有不增加字段,在原有字段的基础上,对字段里面的null值进行填充的方法呢
- Anti chicken soup speech
- 深度学习系列47:styleGAN总结
- 746. 使用最小花费爬楼梯-动态规划
- 407 stack and queue (232. implementing queue with stack, 225. implementing stack with queue)
猜你喜欢

excel高级绘图技巧100讲(八)-Excel绘制WIFI图

redux Actions may not have an undefined “type“ property. Have you misspelled a constant?

Run typescript code directly using TS node

WPF command directive and inotifypropertychanged

Project_ Filter to solve Chinese garbled code
![[project training] multi segment line expanded to parallel line](/img/f2/ee4985fd2454bf00d600e34a818f2d.png)
[project training] multi segment line expanded to parallel line

C language learning summary

Chrome remove duplicate bookmarks

正则表达式图文超详细总结不用死记硬背(上篇)
![[bull Chinese document] queue package used to process distributed jobs and messages in nodejs](/img/f9/1bd79d3754c1b4d1b114d02283f95e.png)
[bull Chinese document] queue package used to process distributed jobs and messages in nodejs
随机推荐
Centos7 MySQL records
406 double pointer (27. remove elements, 977. square of ordered array, 15. sum of three numbers, 18. sum of four numbers)
TP6 安装拓展
Influence of steam education on domestic college students
数据统计与分析基础 实验一 基本语法及运算
Swagger3 integrates oauth2 authentication token
MySQL mvcc multi version concurrency control
【STL】pair用法总结
315. 计算右侧小于当前元素的个数
322. 零钱兑换
JS dynamically creates a href circular download file. Only 10 or a fixed number of files can be downloaded
Children's programming for comprehensively cultivating students' mental thinking
GIS实战应用案例100篇(七十九)-多规整合底图的制作要点
295. 数据流的中位数
897. 递增顺序搜索树
QT设计师无法修改窗口大小,无法通过鼠标拖动窗口改变大小的解决方案
core. What is JS ---kalrry
XML DTD record
正则表达式图文超详细总结不用死记硬背(上篇)
【毕业季·进击的技术er】自己的选择,跪着也要走