# 奇安信21秋招算法岗笔试题

## 测试样例

输入
[1,1,2]

输出
2


## 方法1：

res_list = []
for one in  itertools.permutations([1,1,2]):
res_list.append(one)
res_list
>> [(1, 1, 2), (1, 2, 1), (1, 1, 2), (1, 2, 1), (2, 1, 1), (2, 1, 1)]


import itertools

class Solution:
def helper(self , num_list):
tmp_list = itertools.permutations(num_list)
res_list=[]
alist = []
for one in  tmp_list:
res_list.append(one)
for i in res_list:
x = ''.join(tuple(map(str,i)))
alist.append(x)
return alist
def reletive_7(self , digit):
# write code here
count = 0
alist = self.helper(digit)
for i in range(len(alist)):
if int(alist[i])%7 == 0:
count += 1
return count

s = Solution()
s.reletive_7([1,1,2])
>> 2


## 方法2

def permutation(digit):
s= []
for i in digit:
s.append(str(i))
c, res = list(s), []
def dfs(x):
if x == len(c) - 1:
res.append(''.join(c)) # 添加排列方案
return
dic = []
for i in range(x, len(c)):
#if c[i] in dic: continue # 重复，因此剪枝
dic.append(c[i])
c[i], c[x] = c[x], c[i] # 交换，将 c[i] 固定在第 x 位
dfs(x + 1) # 开启固定第 x + 1 位字符
c[i], c[x] = c[x], c[i] # 恢复交换
dfs(0)
result = []
for i in res:
if int(i) % 7 == 0:
result.append((int(i)))

return len(result)
permutation([1,1,2])
>> 2

09-17 8144

05-03 3620
10-13 639
01-29
08-20 1403
09-15
09-09 1346