leetcode : Permutations II
runtime 4 ms, beats 94.44% of cpp submissions
O(n x n!) solution with explanation
tags: backtracking
๐ link
๐ description
็ตฆๅฎไธๅ้ฃๅ nums ๏ผๅๅณ่ฉฒ้ฃๅๅ ็ด ๅฏ็ข็็ๆๆๆๅ็ตๅๆนๅผ๏ผๅ ็ด ๆๅฏ่ฝ ้่ค ๏ผๅฏไปฅไปฅไปปไฝ้ ๅบๅๅณ๏ผไฝๆฏ็ตๅไธ่ฝ้่คใ
ex.
    Input: nums = [1,1,2]
    Output:
        [[1,1,2],
        [1,2,1],
        [2,1,1]]
๐ง solution
Permutations
solution
ๅฏไปฅๅฉ็จ่ไธไธ้ก้กไผผ็ๆถๆงไพๅฎๆ๏ผไฝๆฏๅ ็บๅ
็ด ๆ้่ค๏ผๆไปฅ้ๆๅ้่ฆๅฟ
้ ไฝฟ็จ set ไพๅป้ใ
โณ time complexity
ๅ
ฑๆ n! ๅ่งฃ (ๆๅฃ็ๆณไธๅ
็ด ๆฒๆ้่ค)๏ผๆฏๅ่งฃ้ฝ็ถ้ n ๆฌกไบคๆ๏ผๆ้่ค้ๅบฆ O(n x n!)
็ธฝๆ้่ค้ๅบฆ O(n x n!)
๐ code
1  | class Solution {  | 
