|
1 |
| -# [2291. Maximum Profit From Trading Stocks](https://leetcode.cn/problems/maximum-profit-from-trading-stocks) |
| 1 | +# [2291. 最大股票收益](https://leetcode.cn/problems/maximum-profit-from-trading-stocks) |
2 | 2 |
|
3 | 3 | [English Version](/solution/2200-2299/2291.Maximum%20Profit%20From%20Trading%20Stocks/README_EN.md)
|
4 | 4 |
|
5 | 5 | ## 题目描述
|
6 | 6 |
|
7 | 7 | <!-- 这里写题目描述 -->
|
8 | 8 |
|
9 |
| -<p>You are given two <strong>0-indexed</strong> integer arrays of the same length <code>present</code> and <code>future</code> where <code>present[i]</code> is the current price of the <code>i<sup>th</sup></code> stock and <code>future[i]</code> is the price of the <code>i<sup>th</sup></code> stock a year in the future. You may buy each stock at most <strong>once</strong>. You are also given an integer <code>budget</code> representing the amount of money you currently have.</p> |
| 9 | +<p>给你两个下标从 <strong>0</strong> 开始的数组 <code>present</code> 和 <code>future</code> ,<code>present[i]</code> 和 <code>future[i]</code> 分别代表第 <code>i</code> 支股票现在和将来的价格。每支股票你最多购买 <strong>一次</strong> ,你的预算为 <code>budget</code> 。</p> |
10 | 10 |
|
11 |
| -<p>Return <em>the maximum amount of profit you can make.</em></p> |
| 11 | +<p>求最大的收益。</p> |
12 | 12 |
|
13 | 13 | <p> </p>
|
14 |
| -<p><strong class="example">Example 1:</strong></p> |
| 14 | + |
| 15 | +<p><strong>示例 1:</strong></p> |
15 | 16 |
|
16 | 17 | <pre>
|
17 |
| -<strong>Input:</strong> present = [5,4,6,2,3], future = [8,5,4,3,5], budget = 10 |
18 |
| -<strong>Output:</strong> 6 |
19 |
| -<strong>Explanation:</strong> One possible way to maximize your profit is to: |
20 |
| -Buy the 0<sup>th</sup>, 3<sup>rd</sup>, and 4<sup>th</sup> stocks for a total of 5 + 2 + 3 = 10. |
21 |
| -Next year, sell all three stocks for a total of 8 + 3 + 5 = 16. |
22 |
| -The profit you made is 16 - 10 = 6. |
23 |
| -It can be shown that the maximum profit you can make is 6. |
| 18 | +<strong>输入:</strong>present = [5,4,6,2,3], future = [8,5,4,3,5], budget = 10 |
| 19 | +<strong>输出:</strong>6 |
| 20 | +<strong>解释:</strong>你可以选择购买第 0,3,4 支股票获得最大收益:6 。总开销为:5 + 2 + 3 = 10 , 总收益是: 8 + 3 + 5 - 10 = 6 。 |
24 | 21 | </pre>
|
25 | 22 |
|
26 |
| -<p><strong class="example">Example 2:</strong></p> |
| 23 | +<p><strong>示例 2:</strong></p> |
27 | 24 |
|
28 | 25 | <pre>
|
29 |
| -<strong>Input:</strong> present = [2,2,5], future = [3,4,10], budget = 6 |
30 |
| -<strong>Output:</strong> 5 |
31 |
| -<strong>Explanation:</strong> The only possible way to maximize your profit is to: |
32 |
| -Buy the 2<sup>nd</sup> stock, and make a profit of 10 - 5 = 5. |
33 |
| -It can be shown that the maximum profit you can make is 5. |
| 26 | +<strong>输入:</strong>present = [2,2,5], future = [3,4,10], budget = 6 |
| 27 | +<strong>输出:</strong>5 |
| 28 | +<strong>解释:</strong>你可以选择购买第 2 支股票获得最大收益:5 。总开销为:5 , 总收益是: 10 - 5 = 5 。 |
34 | 29 | </pre>
|
35 | 30 |
|
36 |
| -<p><strong class="example">Example 3:</strong></p> |
| 31 | +<p><strong>示例 3:</strong></p> |
37 | 32 |
|
38 | 33 | <pre>
|
39 |
| -<strong>Input:</strong> present = [3,3,12], future = [0,3,15], budget = 10 |
40 |
| -<strong>Output:</strong> 0 |
41 |
| -<strong>Explanation:</strong> One possible way to maximize your profit is to: |
42 |
| -Buy the 1<sup>st</sup> stock, and make a profit of 3 - 3 = 0. |
43 |
| -It can be shown that the maximum profit you can make is 0. |
| 34 | +<strong>输入:</strong>present = [3,3,12], future = [0,3,15], budget = 10 |
| 35 | +<strong>输出:</strong>0 |
| 36 | +<strong>解释:</strong>你无法购买唯一一支正收益股票 2 ,因此你的收益是 0 。 |
44 | 37 | </pre>
|
45 | 38 |
|
46 | 39 | <p> </p>
|
47 |
| -<p><strong>Constraints:</strong></p> |
| 40 | + |
| 41 | +<p><strong>提示:</strong></p> |
48 | 42 |
|
49 | 43 | <ul>
|
50 | 44 | <li><code>n == present.length == future.length</code></li>
|
|
0 commit comments