2021欢聚时代秋招(自然语言处理岗)编程题解法
"""
输入正整数n,计算从集合0,1....n当中可以组成的偶数的数量(偶数中不能有重复的数值)
"""
class Solution:
def get_even_num(self, n):
# write code here
if n == 0:
return 1
ou = n // 2 + 1
result = ou
for i in range(1, n + 1):
step = i
a = ou
while step>0:
a = a*(n-step+1)
step -= 1
b = ou-1
if i-1>0:
step = n-1
count = i-1
# print("step:",step,"count:", count)
while count>0:
b = b*step
count -= 1
step -= 1
result += a-b
# print(a,b)
# print(result)
return result
Solution().get_even_num(4)
#欢聚集团##笔试题目#
睿联技术公司福利 62人发布
查看19道真题和解析