【发布时间】:2015-04-28 13:07:47
【问题描述】:
我正在学习 Codility Counting Lesson (https://codility.com/media/train/2-CountingElements.pdf),我需要帮助来了解最快的解决方案。
我想知道计数功能是什么意思:
count = counting(A, m)
问题:
给定一个整数 m (1
def fast_solution(A, B, m):
n = len(A)
sum_a = sum(A)
sum_b = sum(B)
d = sum_b - sum_a
if d % 2 == 1:
return False
d //= 2
count = counting(A, m)
for i in xrange(n):
if 0 <= B[i] - d and B[i] - d <= m and count[B[i] - d] > 0:
return True
return False
【问题讨论】:
-
counting不是 Python 中的内置函数,它必须来自它们。能否提供一下出处?