021/Python

/Python/3.6_168.py
# Python 3.6.2
def solution(A):
# write your code in Python 3.6
if not A:
return 1
n = len(A)
s = 0
for i in range(n):
s += A[i]
t = s - n + 1
return t

if __name__ == '__main__':
A = [10, 3, 7, -3, 9, 2]
print(solution(A))

/Python/4.1_100.py
# Python 3.6.2
def solution(A):
# write your code in Python 3.6
if not A:
return 0

n = len(A)
A.sort()
if A[0] > 0:
return 0
if A[n-1] < 0:
return 0

s = A[0]
for i in range(1, n):
if s * 2 < A[i] or s * -2 > A[i]:
return 0
else:
s = A[i]

return 1

if __name__ == '__main__':
A = [2, 3, 5, -7, 1, 3, -2, -3, 9]
print(solution(A))

/Python/1.5_100.py
# Python 3.6.2
def solution(A):
# write your code in Python 3.6
if not A:
return 1
n = len(A)
s = 0
for i in range(n):
s += A[i]

s = s - n + 1
return s

if __name__ == '__main__':
A = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
print(solution(A))

/Python/3.1_100.py
# Python 3.6.2
def solution(A):
# write your code in Python 3.6
if not A:
return 0

n = len(A)
A.sort()

if A[0] > 0:
return 0

if A[n-1] < 0:
return 0

for i in range(n - 1):
if A[i+1] - A[i] > 1:
return 0

return 1

if __name__ == '__main__':
A = [0, 1, 2, 4, 5, 7]
print(solution(A))

/Python/3.3_100.py
# Python 3.6.2
def solution(A):
# write your code in Python 3.6
if not A:
return 0

n = len(A)
A.sort()
s = 0
for i in range(n):
s += A[i]

s = s - n + 1

return s

if __name__ == '__main__':
A = [3, 4, 5, 1, 2]
print(solution(A))

/Python/1.1_100.py
# Python 3.6.2
def solution(A):
# write your code in Python 3.6
if not A:
return 0

n = len(A)
A.sort()

if A[0] > 0:
return 0

if A[n-1] < 0:
return 0

for i in range(n - 1):
if A[i+1] - A[i] > 1:
return 0

return 1

if __name__ == '__main__':
A = [3, 4, 5, 1, 2]
print(solution(A))

/Python/3.4_100.py
# Python 3.6.2
def solution(A):
# write your code in Python 3.6
if not A:
return 0

n = len(A)
A.sort()

if A[0] > 0:
return 0

if A[n-1] < 0:
return 0

for i in range(n - 1):
if A[i+1] - A[i] > 1:
return 0

return 1

if __name__ == '__main__':
A = [3, 4, 5, 1, 2]
print(solution(A))

/Python/3.2_100.py
# Python 3.6.2
def solution(A):
# write your code in Python 3.6
if not A:
return 0

n = len(A)
A.sort()

if A[0] > 0:
return 0

if A[n-1] < 0:
return 0

for i in range(n - 1):
if A[i+1] - A[i] > 1:
return 0

return 1

if __name__ == '__main__':
A = [3, 4, 5, 1, 2]
print(solution(A))

/Python/1.100.py
# Python 3