def countArrangement(self, N):
"""
:type N: int
:rtype: int
"""
def judge(num, pos):
if not (num % pos) or not (pos % num):
return True
return False
from itertools import permutations
seq = range(1, N + 1)
seq_len = len(seq)
count = 0
for arrangement in (permutations(seq, seq_len)):
for index, ele in enumerate(arrangement, 1):
res = judge(ele, index)
if not res:
break
else:
count += 1
return count
BeautifulArrangement.py 文件源码
python
阅读 39
收藏 0
点赞 0
评论 0
评论列表
文章目录