[Swift] ์์ด๊ณผ ์กฐํฉ ๊ฐ๋จํ ๊ตฌํ๊ธฐ
ยท
๐ ์ฝํ
/๊ฟํ
import Foundation let arr = [1, 2, 3] let n = 3 // O(n!) func perm(_ current: [Int]) { if current.count > n { return } arr.forEach { perm(current + [$0]) } if current.count < n { return } print(current) } perm([]) // O(2^n) func comb(_ current: [Int], _ idx: Int) { guard current.count < n else { print(current) return } for i in idx..