当前位置:网站首页>Interview questions for HW (OD) post
Interview questions for HW (OD) post
2022-07-01 06:28:00 【ydfind】
The rare treasures in the title Switch to The concept of stock is well understood , If you knew it would rise tomorrow , Which buy today , Sell... Tomorrow . Tomorrow , If you know it will rise the day after tomorrow , Then buy tomorrow , Backstage sales … By analogy , Must get the maximum benefit
/**
* HW Two sides interviewer The problem is
*/
public class MainTest {
// Suppose you are an antique dealer , Recently, a rare treasure has appeared on the market ,
/**
*
* A stock , You can predict its future N The market price of each day ( Given an array , The subscript is no i God , The value is No i Day price ),
* You want to make a profit by buying and selling , Please calculate the maximum profit you can make .
*/
public int getMaxProfit(int[] prices) {
int last = prices[0];
int profit = 0;
for (int i = 1; i < prices.length; i++) {
if (prices[i] > last) {
profit += prices[i] - last;
}
last = prices[i];
}
return profit;
}
@Test
public void testExample1() {
int[] arr = new int[]{1, 3, 1, 10, 100, 1000};
Assert.assertEquals(1001, getMaxProfit(arr));
arr = new int[]{2, 4, 5, 2, 9, 7, 8, 10, 8};
Assert.assertEquals(13, getMaxProfit(arr));
}
}
边栏推荐
- [network security tool] what is the use of USB control software
- 交换机配置软件具有的作用
- [unity shader custom material panel part I]
- C语言课设学生信息管理系统(大作业)
- TCL statements in SQL (transaction control statements)
- B-树系列
- High order binary search tree
- Three minutes to quickly understand the whole process of website development
- Mysql 表分区创建方法
- 下载外文期刊的方法
猜你喜欢

Redis安装到Windows系统上的详细步骤

Free trial of self-developed software noisecreater1.1
![阿里OSS Postman Invalid according to Policy: Policy Condition failed: [“starts-with“, “$key“, “test/“]](/img/3c/7684b7c594f7871471f89007294703.png)
阿里OSS Postman Invalid according to Policy: Policy Condition failed: [“starts-with“, “$key“, “test/“]

Detailed steps for installing redis on Windows system

高阶-二叉平衡树
![[ManageEngine] how to realize network automatic operation and maintenance](/img/8a/75332d3180f92c6a6482d881032bbf.png)
[ManageEngine] how to realize network automatic operation and maintenance

下载外文期刊的方法

Excel visualization

C语言课设物业费管理系统(大作业)
![[unity shader amplify shader editor (ASE) Chapter 9]](/img/f5/f0f6786406e149187e71c8e12cde0d.png)
[unity shader amplify shader editor (ASE) Chapter 9]
随机推荐
Internet worm
根据输入画有向图
H5网页判断是否安装了某个APP,安装则跳转未安装则下载的方案总结
[self use of advanced mathematics in postgraduate entrance examination] advanced mathematics Chapter 1 thinking map in basic stage
C语言课设职工信息管理系统(大作业)
自开发软件NoiseCreater1.1版本免费试用
On siem
HCM Beginner (II) - information type
C语言课设工资管理系统(大作业)
libpng12.so. 0: cannot open shared object file: no such file or directory
SQL学习笔记九种连接2
Mysql 表分区创建方法
Lxml module (data extraction)
基金定投是高风险产品吗?
@Propagation property of transactional requires_ New in-depth understanding
C语言课设图书信息管理系统(大作业)
下载外文期刊的方法
C language course set up salary management system (big homework)
【ManageEngine卓豪】网络运维管理是什么,网络运维平台有什么用
mysql约束学习笔记