46. Permutations - example

元素 unique, 不允許重複使用

但數字可能會在前面出現, 所以需要 used 限制使用過的, 不能靠 nature order, i = start 來限制用過的

use list.contains => O(n)

time: O(n!*n*n) or just O(n!)

space: O(n!*n)

這就像是 backtracking 的一個一貫作法

use used[] , replace list.contains

time: O(n!*n) or O(n!)

space: O(n!*n) or O(n!)

Last updated

Was this helpful?