This commit is contained in:
2025-11-16 21:10:46 +08:00
parent 6b74b03d0f
commit f5ce056f2d
3 changed files with 75 additions and 0 deletions

20
25/11/1513.cpp Normal file
View File

@@ -0,0 +1,20 @@
#include <string>
int numSub(std::string s) {
int count = 0;
long ans = 0;
int mod = 1e9+7;
int n = s.length();
for(int i = 0;i<n;i++){
if(s[i] == '1'){
count++;
}
if(s[i] == '0' || i == n-1){
while (count != 0) {
ans += count--;
}
}
}
return int(ans % mod);
}

17
25/11/3228-unfinish.cpp Normal file
View File

@@ -0,0 +1,17 @@
#include <string>
int maxOperations(std::string s) {
int countOne = 0;
int ans = 0;
for (int i = 0; i < s.length(); i++) {
if (s[i] == '0') {
while ((i + 1) < s.length() && s[i + 1] == '0') {
i++;
}
ans += countOne;
} else {
countOne++;
}
}
return ans;
}

38
25/11/go/2654.go Normal file
View File

@@ -0,0 +1,38 @@
package B
func minOperations(nums []int) int {
n, gcdAll, cnt1 := len(nums), 0, 0
for _, x := range nums {
gcdAll = gcd(gcdAll, x)
if x == 1 {
cnt1++
}
}
if gcdAll > 1 {
return -1
}
if cnt1 > 0 {
return n - cnt1
}
minSize := n
for i := range nums {
g := 0
for j, x := range nums[i:] {
g = gcd(g, x)
if g == 1 {
// 这里本来是 j+1把 +1 提出来合并到 return 中
minSize = min(minSize, j)
break
}
}
}
return minSize + n - 1
}
func gcd(a, b int) int {
for a != 0 {
a, b = b%a, a
}
return b
}