Skip to content

Commit b47f3cb

Browse files
refactor 689
1 parent e0ce75b commit b47f3cb

File tree

1 file changed

+6
-23
lines changed
  • src/main/java/com/fishercoder/solutions

1 file changed

+6
-23
lines changed

src/main/java/com/fishercoder/solutions/_689.java

Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,17 @@
11
package com.fishercoder.solutions;
22

3-
/**
4-
* 689. Maximum Sum of 3 Non-Overlapping Subarrays
5-
*
6-
* In a given array nums of positive integers, find three non-overlapping subarrays with maximum sum.
7-
* Each subarray will be of size k, and we want to maximize the sum of all 3*k entries.
8-
* Return the result as a list of indices representing the starting position of each interval (0-indexed).
9-
* If there are multiple answers, return the lexicographically smallest one.
10-
11-
Example:
12-
Input: [1,2,1,2,6,7,5,1], 2
13-
Output: [0, 3, 5]
14-
Explanation: Subarrays [1, 2], [2, 6], [7, 5] correspond to the starting indices [0, 3, 5].
15-
We could have also taken [2, 1], but an answer of [1, 3, 5] would be lexicographically larger.
16-
17-
Note:
18-
nums.length will be between 1 and 20000.
19-
nums[i] will be between 1 and 65535.
20-
k will be between 1 and floor(nums.length / 3).
21-
*/
223
public class _689 {
234
public static class Solution1 {
24-
/**we basically need to find the interval (i, i+k-1) as the middle interval, where k <= i <= n-2k
5+
/**
6+
* we basically need to find the interval (i, i+k-1) as the middle interval, where k <= i <= n-2k
257
* then this interval (0, i-1) will be the left interval
268
* the interval (i+k, n-1) will be the right interval.
27-
*
9+
* <p>
2810
* Please pay special attention to the variable name I use here: this `k` is not a random one, it's the `k`
2911
* from the passed in parameter.
30-
*
31-
* Credit: https://discuss.leetcode.com/topic/105577/c-java-dp-with-explanation-o-n/*/
12+
* <p>
13+
* Credit: https://discuss.leetcode.com/topic/105577/c-java-dp-with-explanation-o-n/
14+
*/
3215
public int[] maxSumOfThreeSubarrays(int[] nums, int k) {
3316
if (nums == null || nums.length == 0) {
3417
return new int[]{};

0 commit comments

Comments
 (0)