【发布时间】:2021-06-29 22:42:28
【问题描述】:
仅给定一个由 0 和 1 组成的数组以及另一个范围数组。 返回一个数组,其中每组范围内的零个数。
输入
bits = [1,1,0,1,0,1,1,0,1,0,1]
ranges = [[0,3],[1,4],[5,7],[4,8],[7,10]]
输出:
result = [1,2,1,2,2]
【问题讨论】:
仅给定一个由 0 和 1 组成的数组以及另一个范围数组。 返回一个数组,其中每组范围内的零个数。
输入
bits = [1,1,0,1,0,1,1,0,1,0,1]
ranges = [[0,3],[1,4],[5,7],[4,8],[7,10]]
输出:
result = [1,2,1,2,2]
【问题讨论】:
在位数组中创建一个零的数量的辅助数组,直到该点。
bits = [1,1,0,1,0,1,1,0,1,0,1]
sum = [0,0,1,1,2,2,2,3,3,4,4]
[0,3] 的结果就是 sum[3]-sum[0]。
Make a helper array with the running sum of zeroes.
then subtract the the value at start of range from the value at end of range.
push result
repeat
【讨论】: