""" 输入正整数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)
全部评论
(3) 回帖