|
1 | | -## 题目地址 |
2 | | -https://leetcode.com/problems/maximum-sum-of-two-non-overlapping-subarrays/ |
| 1 | +## 题目地址(1031. 两个非重叠子数组的最大和) |
| 2 | +https://leetcode-cn.com/problems/maximum-sum-of-two-non-overlapping-subarrays/ |
3 | 3 |
|
4 | 4 | ## 题目描述 |
5 | 5 |
|
6 | 6 | ``` |
7 | | -Given an array A of non-negative integers, return the maximum sum of elements in two non-overlapping (contiguous) subarrays, which have lengths L and M. (For clarification, the L-length subarray could occur before or after the M-length subarray.) |
| 7 | +给出非负整数数组 A ,返回两个非重叠(连续)子数组中元素的最大和,子数组的长度分别为 L 和 M。(这里需要澄清的是,长为 L 的子数组可以出现在长为 M 的子数组之前或之后。) |
8 | 8 |
|
9 | | -Formally, return the largest V for which V = (A[i] + A[i+1] + ... + A[i+L-1]) + (A[j] + A[j+1] + ... + A[j+M-1]) and either: |
| 9 | +从形式上看,返回最大的 V,而 V = (A[i] + A[i+1] + ... + A[i+L-1]) + (A[j] + A[j+1] + ... + A[j+M-1]) 并满足下列条件之一: |
10 | 10 |
|
11 | | -0 <= i < i + L - 1 < j < j + M - 1 < A.length, or |
| 11 | + |
| 12 | +
|
| 13 | +0 <= i < i + L - 1 < j < j + M - 1 < A.length, 或 |
12 | 14 | 0 <= j < j + M - 1 < i < i + L - 1 < A.length. |
13 | | - |
| 15 | + |
14 | 16 |
|
15 | | -Example 1: |
| 17 | +示例 1: |
16 | 18 |
|
17 | | -Input: A = [0,6,5,2,2,5,1,9,4], L = 1, M = 2 |
18 | | -Output: 20 |
19 | | -Explanation: One choice of subarrays is [9] with length 1, and [6,5] with length 2. |
20 | | -Example 2: |
| 19 | +输入:A = [0,6,5,2,2,5,1,9,4], L = 1, M = 2 |
| 20 | +输出:20 |
| 21 | +解释:子数组的一种选择中,[9] 长度为 1,[6,5] 长度为 2。 |
| 22 | +示例 2: |
21 | 23 |
|
22 | | -Input: A = [3,8,1,3,2,1,8,9,0], L = 3, M = 2 |
23 | | -Output: 29 |
24 | | -Explanation: One choice of subarrays is [3,8,1] with length 3, and [8,9] with length 2. |
25 | | -Example 3: |
| 24 | +输入:A = [3,8,1,3,2,1,8,9,0], L = 3, M = 2 |
| 25 | +输出:29 |
| 26 | +解释:子数组的一种选择中,[3,8,1] 长度为 3,[8,9] 长度为 2。 |
| 27 | +示例 3: |
26 | 28 |
|
27 | | -Input: A = [2,1,5,6,0,9,5,0,3,8], L = 4, M = 3 |
28 | | -Output: 31 |
29 | | -Explanation: One choice of subarrays is [5,6,0,9] with length 4, and [3,8] with length 3. |
30 | | - |
| 29 | +输入:A = [2,1,5,6,0,9,5,0,3,8], L = 4, M = 3 |
| 30 | +输出:31 |
| 31 | +解释:子数组的一种选择中,[5,6,0,9] 长度为 4,[0,3,8] 长度为 3。 |
| 32 | + |
31 | 33 |
|
32 | | -Note: |
| 34 | +提示: |
33 | 35 |
|
34 | 36 | L >= 1 |
35 | 37 | M >= 1 |
36 | 38 | L + M <= A.length <= 1000 |
37 | 39 | 0 <= A[i] <= 1000 |
| 40 | +
|
38 | 41 | ``` |
39 | 42 |
|
40 | 43 | ## 前置知识 |
|
0 commit comments