https://leetcode.cn/problems/maximum-beauty-of-an-array-after-applying-operation/submissions/596274340/
这题猜测的有意思
```js
var maximumBeauty = function (nums, k) {
nums = nums.sort((a, b) => a - b);
let left = 0;
let ans = 0;
for (let index = 0; index < nums.length; index++) {
const num = nums;
while (nums + 2*k < num) {
left++;
}
ans = Math.max(ans, index - left + 1);
}
return ans
};
```
https://leetcode.cn/problems/range-addition-ii/submissions/596274960/
过
```js
var maxCount = function (m, n, ops) {
if(ops.length==0){
return m*n
}
let minA = Number.MAX_SAFE_INTEGER,
minB = Number.MAX_SAFE_INTEGER;
for (let index = 0; index < ops.length; index++) {
const = ops;
minA=Math.min(minA,a)
minB=Math.min(minB,b)
}
return minA*minB
};
```
https://leetcode.cn/problems/maximize-the-confusion-of-an-exam/submissions/596283440/
过
```js
var maxConsecutiveAnswers = function(answerKey, k) {
answerKey=answerKey.split("")
const r1=maxSubarrayLength(answerKey,"F",k)
const r2= maxSubarrayLength(answerKey,"T",k)
return Math.max(r1,r2)
};
var maxSubarrayLength = function (nums,error, 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(error) > 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;
};
```
https://leetcode.cn/problems/max-consecutive-ones-iii/submissions/596287052/
过
```js
var maxSubarrayLength = function (nums,error, 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(error) > 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;
};
/**
* @param {number[]} nums
* @param {number} k
* @Return {number}
*/
var longestOnes = function(nums, k) {
return maxSubarrayLength(nums,0,k)
};
```
https://leetcode.cn/problems/minimum-operations-to-reduce-x-to-zero/submissions/596287260/
神经刀了
```js
var minOperations = function (nums, x) {
let total = 0;
let right = 0;
let times = Number.MAX_SAFE_INTEGER;
for (let index = 0; index < nums.length; index++) {
total += nums;
right = index;
if (total >= x) {
break;
}
}
if (total == x) {
times = right + 1;
}
let left = 0;
for (let index = right; index >= 0; index--) {
total -= nums;
while (total < x && (nums.length - 1 - left) >= index) {
total += nums;
left++;
}
if (total == x) {
times = Math.min(times, index + left);
}
}
return times == Number.MAX_SAFE_INTEGER ? -1 : times;
};
```
https://leetcode.cn/problems/frequency-of-the-most-frequent-element/submissions/596358672/
秒了
```jsj
var maxFrequency = function (nums, k) {
nums = nums.sort((a, b) => a - b);
let left = 0;
let ans = 0;
let total = 0;
for (let index = 0; index < nums.length; index++) {
const num = nums;
let range = index - left + 1;
total += num;
while (total + k < range * num) {
total -= nums;
left++;
range = index - left + 1;
}
ans = Math.max(ans,range);
}
return ans
};
```
https://leetcode.cn/problems/take-k-of-each-character-from-left-and-right/submissions/596368346/
过了,爽
```js
var takeCharacters = function (s, k) {
const arr = [];
for (let index = 0; index < s.length; index++) {
const char = s;
if (char == "a") {
arr.push(0);
} else if (char == "b") {
arr.push(1);
} else if (char == "c") {
arr.push(2);
}
}
const times = ;
let right = 0;
while ((times < k || times < k || times < k) && right < s.length) {
times]++;
right++;
}
if ((times < k || times < k || times < k) && right >= s.length) {
return -1;
}
let ans = right;
let border = s.length - 1;
let left = right - 1;
while (left >= 0) {
times]--;
left--;
while ((times < k || times < k || times < k) && border > left) {
times]++;
border--;
}
while (times] - 1 > k) {
times]--;
left--;
}
ans = Math.min(ans, left + (s.length - border));
}
return ans;
};
```
https://leetcode.cn/problems/find-the-longest-equal-subarray/submissions/596396081/
起飞,第一次1900分题
```js
var longestEqualSubarray = function (nums, k) {
const cache = new Map();
for (let index = 0; index < nums.length; index++) {
const num = nums;
if (!cache.has(num)) {
cache.set(num, []);
}
cache.get(num).push(index);
}
let ans = 0;
for (const of cache) {
if(ans>=arr.length){
continue;
}
let left = 0;
for (let right = 0; right < arr.length; right++) {
while (arr - arr - (right - left) > k) {
left++;
}
ans = Math.max(ans, right - left + 1);
}
}
return ans
};
```
https://leetcode.cn/problems/valid-palindrome-ii/submissions/596421486/
秒
```js
var validPalindrome = function (s) {
const checkEqual = (l, r, jump) => {
let left = l,
right = r;
while (left < right) {
if (s == s) {
left++;
right--;
} else if (jump == false) {
return (
checkEqual(left+1, right, true) || checkEqual(left, right-1, true)
);
} else {
return false;
}
}
return true;
};
return checkEqual(0, s.length - 1, false);
};
```
https://leetcode.cn/problems/maximum-white-tiles-covered-by-a-carpet/submissions/596425043/
秒了
```js
var maximumWhiteTiles = function (tiles, carpetLen) {
tiles = tiles.sort((a, b) => a - b);
let left = 0;
let total = 0;
let ans = 0;
for (const of tiles) {
total += r - l + 1;
let pos = r - carpetLen + 1;
while (pos > tiles) {
total -= tiles - tiles + 1;
left++;
}
let sub = 0;
if (pos > tiles && pos <= tiles) {
sub = pos - tiles;
}
ans = Math.max(ans, total - sub);
}
return ans;
};
```