This commit is contained in:
kkunkka
2025-05-11 12:32:49 +08:00
parent c7ff770448
commit 1d08616458

View File

@@ -3,11 +3,25 @@ package com.dota.slidingWindow._2106;
class Solution {
public static void main(String[] args) {
new Solution().maxTotalFruits(new int[][]{
{0, 7}, {7, 4}, {9, 10}, {12, 6}, {14, 8},
{16, 5}, {17, 8}, {19, 4}, {20, 1}, {21, 3},
{24, 3}, {25, 3}, {26, 1}, {28, 10}, {30, 9},
{31, 6}, {32, 1}, {37, 5}, {40, 9}
}, 21, 30);
{0, 9},
{5, 6},
{8, 9},
{11, 3},
{14, 9},
{16, 5},
{17, 1},
{20, 6},
{21, 5},
{23, 7},
{24, 3},
{26, 7},
{28, 4},
{29, 8},
{30, 7},
{31, 2},
{36, 8},
{38, 7}
}, 23, 41);
}
public int maxTotalFruits(int[][] fruits, int startPos, int k) {
@@ -56,11 +70,11 @@ class Solution {
sum -= dp[i];
}
l--;
if (l > 0 && l < dp.length && l < startPos) {
if (l >= 0 && l < dp.length && l < startPos) {
sum += dp[l];
}
l--;
if (l > 0 && l < dp.length && l < startPos) {
if (l >= 0 && l < dp.length && l < startPos) {
sum += dp[l];
}