|
1 |
| -# [2355. Maximum Number of Books You Can Take](https://leetcode.cn/problems/maximum-number-of-books-you-can-take) |
| 1 | +# [2355. 你能拿走的最大图书数量](https://leetcode.cn/problems/maximum-number-of-books-you-can-take) |
2 | 2 |
|
3 | 3 | [English Version](/solution/2300-2399/2355.Maximum%20Number%20of%20Books%20You%20Can%20Take/README_EN.md)
|
4 | 4 |
|
5 | 5 | ## 题目描述
|
6 | 6 |
|
7 | 7 | <!-- 这里写题目描述 -->
|
8 | 8 |
|
9 |
| -<p>You are given a <strong>0-indexed</strong> integer array <code>books</code> of length <code>n</code> where <code>books[i]</code> denotes the number of books on the <code>i<sup>th</sup></code> shelf of a bookshelf.</p> |
| 9 | +<p>给定一个长度为 <code>n</code> 的<b> 下标从 0 开始 </b>的整数数组 <code>books</code>,其中 <code>books[i]</code> 表示书架的第 <code>i</code> 个书架上的书的数量。</p> |
10 | 10 |
|
11 |
| -<p>You are going to take books from a <strong>contiguous</strong> section of the bookshelf spanning from <code>l</code> to <code>r</code> where <code>0 <= l <= r < n</code>. For each index <code>i</code> in the range <code>l <= i < r</code>, you must take <strong>strictly fewer</strong> books from shelf <code>i</code> than shelf <code>i + 1</code>.</p> |
| 11 | +<p>你要从书架 <code>l</code> 到 <code>r</code> 的一个 <strong>连续 </strong>的部分中取书,其中 <code>0 <= l <= r < n</code>。对于 <code>l <= i < r</code> 范围内的每个索引 <code>i</code>,你从书架 <code>i</code> 取书的数量必须 <strong>严格小于 </strong>你从书架 <code>i + 1</code> 取书的数量。</p> |
12 | 12 |
|
13 |
| -<p>Return <em>the <strong>maximum</strong> number of books you can take from the bookshelf.</em></p> |
| 13 | +<p>返回<em>你能从书架上拿走的书的 <strong>最大 </strong>数量。</em></p> |
14 | 14 |
|
15 | 15 | <p> </p>
|
16 |
| -<p><strong class="example">Example 1:</strong></p> |
| 16 | + |
| 17 | +<p><strong>示例 1:</strong></p> |
17 | 18 |
|
18 | 19 | <pre>
|
19 |
| -<strong>Input:</strong> books = [8,5,2,7,9] |
20 |
| -<strong>Output:</strong> 19 |
21 |
| -<strong>Explanation:</strong> |
22 |
| -- Take 1 book from shelf 1. |
23 |
| -- Take 2 books from shelf 2. |
24 |
| -- Take 7 books from shelf 3. |
25 |
| -- Take 9 books from shelf 4. |
26 |
| -You have taken 19 books, so return 19. |
27 |
| -It can be proven that 19 is the maximum number of books you can take. |
| 20 | +<strong>输入:</strong> books = [8,5,2,7,9] |
| 21 | +<strong>输出:</strong> 19 |
| 22 | +<strong>解释:</strong> |
| 23 | +- 从书架 1 上取 1 本书。 |
| 24 | +- 从书架 2 上取 2 本书。 |
| 25 | +- 从书架 3 上取 7 本书 |
| 26 | +- 从书架 4 上取 9 本书 |
| 27 | +你已经拿了19本书,所以返回 19。 |
| 28 | +可以证明 19 本是你所能拿走的书的最大数量。 |
28 | 29 | </pre>
|
29 | 30 |
|
30 |
| -<p><strong class="example">Example 2:</strong></p> |
| 31 | +<p><strong>示例 2:</strong></p> |
31 | 32 |
|
32 | 33 | <pre>
|
33 |
| -<strong>Input:</strong> books = [7,0,3,4,5] |
34 |
| -<strong>Output:</strong> 12 |
35 |
| -<strong>Explanation:</strong> |
36 |
| -- Take 3 books from shelf 2. |
37 |
| -- Take 4 books from shelf 3. |
38 |
| -- Take 5 books from shelf 4. |
39 |
| -You have taken 12 books so return 12. |
40 |
| -It can be proven that 12 is the maximum number of books you can take. |
| 34 | +<strong>输入:</strong> books = [7,0,3,4,5] |
| 35 | +<strong>输出:</strong> 12 |
| 36 | +<strong>解释:</strong> |
| 37 | +- 从书架 2 上取 3 本书。 |
| 38 | +- 从书架 3 上取 4 本书。 |
| 39 | +- 从书架 4 上取 5 本书。 |
| 40 | +你已经拿了 12 本书,所以返回 12。 |
| 41 | +可以证明 12 本是你所能拿走的书的最大数量。 |
41 | 42 | </pre>
|
42 | 43 |
|
43 |
| -<p><strong class="example">Example 3:</strong></p> |
| 44 | +<p><strong>示例 3:</strong></p> |
44 | 45 |
|
45 | 46 | <pre>
|
46 |
| -<strong>Input:</strong> books = [8,2,3,7,3,4,0,1,4,3] |
47 |
| -<strong>Output:</strong> 13 |
48 |
| -<strong>Explanation:</strong> |
49 |
| -- Take 1 book from shelf 0. |
50 |
| -- Take 2 books from shelf 1. |
51 |
| -- Take 3 books from shelf 2. |
52 |
| -- Take 7 books from shelf 3. |
53 |
| -You have taken 13 books so return 13. |
54 |
| -It can be proven that 13 is the maximum number of books you can take. |
| 47 | +<strong>输入:</strong> books = [8,2,3,7,3,4,0,1,4,3] |
| 48 | +<strong>输出:</strong> 13 |
| 49 | +<strong>解释:</strong> |
| 50 | +- 从书架 0 上取 1 本书。 |
| 51 | +- 从书架 1 上取 2 本书。 |
| 52 | +- 从书架 2 上取 3 本书。 |
| 53 | +- 从书架 3 上取 7 本书。 |
| 54 | +你已经拿了 13 本书,所以返回 13。 |
| 55 | +可以证明 13 本是你所能拿走的书的最大数量。 |
55 | 56 | </pre>
|
56 | 57 |
|
57 | 58 | <p> </p>
|
58 |
| -<p><strong>Constraints:</strong></p> |
| 59 | + |
| 60 | +<p><strong>提示:</strong></p> |
59 | 61 |
|
60 | 62 | <ul>
|
61 | 63 | <li><code>1 <= books.length <= 10<sup>5</sup></code></li>
|
|
0 commit comments