李恒道 发表于 2025-2-1 01:02:42

https://leetcode.cn/problems/maximum-sum-of-almost-unique-subarray/submissions/596136896/
打完收工
```js
var maxSum = function (nums, m, k) {
let total =0;
let map = new Map();
let max = 0;
for (let index = 0; index < nums.length; index++) {
    const num = nums;
    total += num;
    map.set(num, (map.get(num) ?? 0) + 1);
    if (index >= k) {
      constdeleteNum=nums
      total = total - deleteNum;

      if (map.get(deleteNum) == 1) {
      map.delete(deleteNum);
      } else {
      map.set(deleteNum, map.get(deleteNum) - 1);
      }
    }
    if (index >= k - 1 && map.size >= m) {
      max = Math.max(max, total);
    }
}
return max
};
```

李恒道 发表于 2025-2-1 01:27:53

https://leetcode.cn/problems/maximum-sum-of-distinct-subarrays-with-length-k/submissions/596137960/

```js
var maximumSubarraySum = function(nums, k) {
    let total =0;
    let map = new Map();
    let max = 0;
    for (let index = 0; index < nums.length; index++) {
      const num = nums;
      total += num;
      map.set(num, (map.get(num) ?? 0) + 1);
      if (index >= k) {
          constdeleteNum=nums
      total = total - deleteNum;

      if (map.get(deleteNum) == 1) {
          map.delete(deleteNum);
      } else {
          map.set(deleteNum, map.get(deleteNum) - 1);
      }
      }
      if (index >= k - 1 && map.size ==k) {
      max = Math.max(max, total);
      }
    }
    return max
};
```

李恒道 发表于 2025-2-1 01:57:08

https://leetcode.cn/problems/maximum-points-you-can-obtain-from-cards/submissions/596138941/

```js
var maxScore = function (cardPoints, k) {
let total = 0;
for (let index = 0; index < k; index++) {
    const num = cardPoints;
    total += num;
}
let max = total;
for (let index = 0; index < k; index++) {
    total += cardPoints;
    total -= cardPoints;
    max=Math.max(max,total)
}
return max
};
```

李恒道 发表于 2025-2-1 14:51:59

https://leetcode.cn/problems/maximum-length-substring-with-two-occurrences/submissions/596186730/
过了
```js
var maximumLengthSubstring = function (s) {
let border = 0;
const map = new Map();
let ans = 0;
for (let index = 0; index < s.length; index++) {
    const char = s;

    while (border < s.length && (map.get(s) ?? 0) <2) {
      const borderChar = s;
      map.set(borderChar, (map.get(borderChar) ?? 0) + 1);
      border++;
    }
    ans = Math.max(ans, border - index );
    map.set(char, map.get(char)- 1);
}
return ans
};
```

李恒道 发表于 2025-2-1 15:03:17

https://leetcode.cn/problems/longest-subarray-of-1s-after-deleting-one-element/submissions/596188213/
过了
```js
var longestSubarray = function (nums) {
let hasZero = 0;
let border = 0;
letans=0;
for (let index = 0; index < nums.length; index++) {
    const num = nums;

    while (border < nums.length && hasZero < 2) {
      const borderNum = nums;
      if (borderNum == 0) {
      hasZero++;
      }
      border++;
    }
    ans = Math.max(ans, border - index-hasZero);
    if (num == 0) {
      hasZero--;
    }
}
return ans==nums.length?ans-1:ans
};
```

李恒道 发表于 2025-2-1 15:47:51

https://leetcode.cn/problems/get-equal-substrings-within-budget/submissions/596194779/

```js
var equalSubstring = function (s, t, maxCost) {
const arr = new Array(s.length);
for (let index = 0; index < s.length; index++) {
    const char1 = s;
    const char2 = t;
    arr = Math.abs(char1.charCodeAt() - char2.charCodeAt());
}
let left = 0;
let totalLoss = 0;
let ans = 0;
for (let index = 0; index < arr.length; index++) {
    const num = arr;
    totalLoss += num;
    if (totalLoss > maxCost) {
      totalLoss -= arr;
      left++;
    }
    ans = Math.max(ans, index - left+1);
}
return ans
};
```

李恒道 发表于 2025-2-1 20:54:25

https://leetcode.cn/problems/find-the-longest-semi-repetitive-substring/submissions/596239813/
这个题算是比较有意思的
```js
var longestSemiRepetitiveSubstring = function (s) {
let lastRepeat = -1;
let left = 0;
let ans = 1;
for (let index = 1; index < s.length; index++) {
    const char = s;
    if (s == char && lastRepeat != -1) {
      left = lastRepeat;
    }
    if (s == char) {
      lastRepeat = index;
    }
    ans = Math.max(ans, index - left + 1);
}
return ans;
};
```

李恒道 发表于 2025-2-1 21:55:51

https://leetcode.cn/problems/fruit-into-baskets/submissions/596246584/
过了
```js
var totalFruit = function (fruits) {
let left = 0;
const cache = new Map();
let ans=0;
for (let index = 0; index < fruits.length; index++) {
    const fruit = fruits;
    cache.set(fruit, (cache.get(fruit) ?? 0) + 1);
    while (cache.size > 2) {
      if (cache.get(fruits) == 1) {
      cache.delete(fruits);
      } else {
      cache.set(fruits, (cache.get(fruits) ?? 0) - 1);
      }
      left++
    }
    ans = Math.max(ans, index - left+1 );
}
return ans
};
```

李恒道 发表于 2025-2-1 23:26:00

https://leetcode.cn/problems/maximum-erasure-value/submissions/596267647/

```js
var maximumUniqueSubarray = function (nums) {
let left = 0;
const cache = new Map();
let ans = 0;
let total = 0;
for (let index = 0; index < nums.length; index++) {
    const fruit = nums;
    total += fruit;
    cache.set(fruit, (cache.get(fruit) ?? 0) + 1);
    while (cache.get(fruit)!==1) {
      if (cache.get(nums) == 1) {
      cache.delete(nums);
      } else {
      cache.set(nums, (cache.get(nums) ?? 0) - 1);
      }
      total -= nums;
      left++;
    }
    ans = Math.max(ans, total);
}
return ans;
};

```

李恒道 发表于 2025-2-1 23:46:59

https://leetcode.cn/problems/length-of-longest-subarray-with-at-most-k-frequency/submissions/596270644/

```js
var maxSubarrayLength = function (nums, k) {
let left = 0;
const cache = new Map();
let ans = 0;
for (let index = 0; index < nums.length; index++) {
    const fruit = nums;
    cache.set(fruit, (cache.get(fruit) ?? 0) + 1);
    while (cache.get(fruit)> k) {
      if (cache.get(nums) == 1) {
      cache.delete(nums);
      } else {
      cache.set(nums, (cache.get(nums) ?? 0) - 1);
      }
      left++;
    }
    ans = Math.max(ans, index-left+1);
}
return ans;
};
```
页: 39 40 41 42 43 44 45 46 47 48 [49] 50 51 52 53 54
查看完整版本: 【当前排名42710】挑战leetcode进入前1w名