Re: [問題] 1-9位數不重複印出來 (Python)

作者: changyuheng (張昱珩)   2017-03-30 15:26:23
寫完才看到前面已經有人寫了幾乎一樣的。
DFS 那二份在我的電腦上分別是 10 秒多和 5 秒多,這份 2 秒多。
import itertools, string; print(', '.join(''.join(j)
for i in range(1, int(input()) + 1)
for j in itertools.permutations(string.digits, r=i) if j[0] != '0'))

Links booklink

Contact Us: admin [ a t ] ucptt.com