Sub-array product is less than K

topic

input:[10,5,2,6],100
output:8

Ideas

Violent solution, pay attention to the way of recording count, it may be missed

Code

def count_min_c(nums,k):
    count = 0
    for i in range(len(nums)):
        mul = 1
        for j in range(len(nums)):
            mul *= nums[j]
            if mul>=k:
                break
            count +=1
    return count

Guess you like

Origin blog.csdn.net/aaaqqq1234/article/details/107824304