0926腾讯音乐笔试题解

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提供了大量能使我们快速便捷地处理数据的函数和方法。

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值