gg
This commit is contained in:
38
src/main/java/com/dota/slidingWindow/_1156/Solution.java
Normal file
38
src/main/java/com/dota/slidingWindow/_1156/Solution.java
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
35
src/main/java/com/dota/slidingWindow/_1712/Solution.java
Normal file
35
src/main/java/com/dota/slidingWindow/_1712/Solution.java
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
@@ -2,6 +2,6 @@ package com.dota.slidingWindow._2761;
|
|||||||
|
|
||||||
class Solution {
|
class Solution {
|
||||||
public long continuousSubarrays(int[] nums) {
|
public long continuousSubarrays(int[] nums) {
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
Reference in New Issue
Block a user