计算一组Range所覆盖的不重复整数的个数,求 < O(n*n) 的算法。
def cover(rs: Range*):Int = ???
assert(cover(0 to 4, 1 to 5) == 6)
assert(cover(0 to 4, 1 to 3) == 5)
assert(cover(0 to 4, 6 to 7) == 7)
assert(cover(0 to 4, 6 to 7, 2 to 6) == 8)
计算一组Range所覆盖的不重复整数的个数,求 < O(n*n) 的算法。
def cover(rs: Range*):Int = ???
assert(cover(0 to 4, 1 to 5) == 6)
assert(cover(0 to 4, 1 to 3) == 5)
assert(cover(0 to 4, 6 to 7) == 7)
assert(cover(0 to 4, 6 to 7, 2 to 6) == 8)