腾讯音乐926笔试
求大佬们看下这样为啥0%样例通过,没RE没TLE,自己测的样例都是对的,不知道什么case没考虑到。
题目描述:求数组中所有“元素乘积尾部0大于x的子数组”个数,滑动窗口题
def getSubarrayNum(a, x) -> int: # write code here def is_valid(sum_num, x): sum_zero = 0 while sum_num >= 10: if sum_num % 10 == 0: sum_zero += 1 sum_num = sum_num / 10 return True if sum_zero >= x else False l = r = 0 valid = 0 sum_num = 1 while r < len(a): sum_num = sum_num * a[r] while is_valid(sum_num,x): valid += len(a) - r print(valid, a[l:r+1]) if l < r: sum_num = sum_num / a[l] l += 1 else: break r += 1 valid = valid % (10 ** 9 + 7) return valid