Verified Commit fc35b34e authored by asahiocean's avatar asahiocean 🚀
Browse files
parent fc9741fa
import Foundation
// 46. Permutations
// https://leetcode.com/problems/permutations/
class Solution {
func permute(_ nums: [Int]) -> [[Int]] {
var result = [[Int]](repeating: [], count: 1)
nums.forEach { n in
var arr = [[Int]]()
result.forEach {
for i in 0..<$0.count {
var t = $0
t.insert(n, at: i)
arr.append(t)
}
var t = $0
t.append(n)
arr.append(t)
}
result = arr
}
return result
}
}
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<playground version='5.0' target-platform='ios'>
<timeline fileName='timeline.xctimeline'/>
</playground>
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment