01串修改
题意:给定一个字符串,每次操作可以将一个子串变"00"或者"11",问所有字母相同的最小操作次数。
代码如下(示例):
class Solution:
def minOperations(self , str: str) -> int:
# write code here
# num0,num1 = 0,0
if "1" in str and "0" in str:
num1 = str.count("1")
num0 = str.count("0")
print(num1, num0)
else:
print("dddd")
return 0
a=0
if num0 > num1:
start = 0
while start < len(str) :
# if start + 1 < len(str):
if str[start] == "1":
a += 1
start +=2
else:
start +=1
# else:
# if str[start] == "1":
# a += 1
# break
# start += 2
else:
start = 0
while start < len(str) :
# if start + 1 < len(str):
if str[start] == "0":
a += 1
start +=2
else:
start +=1
return a
# for i in range(len(str)):
##连续子数组数量
题意:求乘积尾零数量大于
x
x的连续子数组数量。
知识点:双指针/二分
代码如下(示例):
class Solution:
def getSubarrayNum(self, a: List[int], x: int) -> int:
# write code here
x = 10 ** x
print(x)
nums, temp = 0, 1
i, j = 0, 0
# while j < len(a):
# temp = 1
while i < len(a):
# temp *= a[i]
temp *= a[i]
if temp % x == 0:
nums += len(a) - i
j += 1
i = j
temp = 1
continue
if j >= len(a):
break
# break
# if a[i] % x == 0:
# nums +=1
i += 1
return nums % 1000000007
总结
提示:这里对文章进行总结:
例如:以上就是今天要讲的内容,本文仅仅简单介绍了pandas的使用,而pandas提供了大量能使我们快速便捷地处理数据的函数和方法。