笔试题:找亲戚(Python列表全排列,找能被7整除的数)
发布日期:2021-05-08 01:41:16 浏览次数:14 分类:技术文章

本文共 374 字,大约阅读时间需要 1 分钟。

对于列表中的数字进行全排列,然后寻找能被7整除的数。

def Method(arr,p,q):    if p==q:        s.append(list(arr))    else:        for i in range(p,q):            arr[i],arr[p]=arr[p],arr[i]            Method(arr,p+1,q)            arr[i],arr[p]=arr[p],arr[i]s=[]res=0arr=list(input().strip().split())Method(arr,0,len(arr))for pl in s:    temp=int(''.join(pl))    if temp%7==0:        res += 1print(res)
上一篇:LeetCode:找重复的数字(Python)
下一篇:LeetCode:数组中出现次数超过一半的数字(Python)

发表评论

最新留言

逛到本站,mark一下
[***.202.152.39]2025年03月20日 17时18分24秒