This commit is contained in:
kkunkka
2025-04-22 14:01:35 +08:00
parent 717657849a
commit e55fc5f313
3 changed files with 74 additions and 1 deletions

View File

@@ -0,0 +1,38 @@
package com.dota.slidingWindow._1156;
class Solution {
public int maxRepOpt1(String text) {
int res = 1;
var dp = new int[26];
for (int i = 0; i < text.length(); i++) {
dp[text.charAt(i) - 'a']++;
}
for (int i = 0; i < 26; i++) {
int cnt = 0;
int other = 0;
int l = 0;
for (int j = 0; j < text.length(); j++) {
if (text.charAt(j) - 'a' == i) {
cnt++;
} else {
other++;
while (other > 1) {
if (text.charAt(l) - 'a' != i) {
other--;
} else {
cnt--;
}
l++;
}
}
int t = 0;
if (cnt < dp[i]) {
t = cnt + 1;
}
res = Math.max(res, t);
}
}
return res;
}
}

View File

@@ -0,0 +1,35 @@
package com.dota.slidingWindow._1712;
class Solution {
public static void main(String[] args) {
new Solution().waysToSplit(new int[]{0,0,3,3});
}
public int waysToSplit(int[] nums) {
long res = 0;
int a = 0;
int sum = 0;
for (int num : nums) {
sum += num;
}
int limit = sum / 3;
for (int i = 0; a <= limit; i++) {
a += nums[i];
if (a>limit) {
break;
}
int j = i + 1;
int t = (sum - a) / 2;
int b = 0;
while (b <= a) {
b += nums[j++];
}
int k = j;
while (b <= t) {
b += nums[k++];
}
res += (k - j);
}
return (int) res%1000000007;
}
}

View File

@@ -2,6 +2,6 @@ package com.dota.slidingWindow._2761;
class Solution {
public long continuousSubarrays(int[] nums) {
return 0;
}
}