Skip to content

Commit

Permalink
Update PermutationsII.swift
Browse files Browse the repository at this point in the history
  • Loading branch information
soapyigu authored Aug 14, 2019
1 parent 99416f1 commit bd85d00
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions DFS/PermutationsII.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@
*/

class PermutationsII {
func permuteUnique(nums: [Int]) -> [[Int]] {
var res = [[Int]]()
var path = [Int]()
var visited = [Bool](count: nums.count, repeatedValue: false)
func permuteUnique(_ nums: [Int]) -> [[Int]] {
var res = [[Int]](), path = [Int](), visited = [Bool](repeating: false, count: nums.count)

let nums = nums.sorted(by: <)

Expand All @@ -22,7 +20,7 @@ class PermutationsII {
private func _dfs(inout res: [[Int]], inout _ path: [Int], _ nums: [Int], inout _ visited: [Bool]) {
// termination case
if path.count == nums.count {
res.append(Array(path))
res.append(path)
return
}

Expand All @@ -38,4 +36,4 @@ class PermutationsII {
path.removeLast()
}
}
}
}

0 comments on commit bd85d00

Please sign in to comment.