[codility]PermMissingElem

Python代码如下:

def solution(A):
    # write your code in Python 2.6
    curSum = 0
    originalSum = 0
    if len(A)%2 == 0:
        originalSum = (len(A)+1)*((len(A)+2)/2)
    else:
        originalSum = ((len(A)+1)/2)*(len(A)+2)
    for i in xrange(0,len(A)):
        curSum += A[i]
    return originalSum-curSum
    pass


你可能感兴趣的:([codility]PermMissingElem)