문제: https://leetcode.com/problems/subsets/
import Foundation
class Solution {
func subsets(_ nums: [Int]) -> [[Int]] {
var result = [[Int]]()
func combination(_ index: Int, _ nowCombi: [Int]) {
result.append(nowCombi)
if nowCombi.count == nums.count {
return
}
for i in index..<nums.count {
combination(i + 1, nowCombi + [nums[i]])
}
}
combination(0, [])
return result
}
}
'알고리즘' 카테고리의 다른 글
[Swift] LeetCode - 297. Serialize and Deserialize Binary Tree (0) | 2022.02.17 |
---|---|
[Swift] LeetCode - 207. Course Schedule (0) | 2022.02.16 |
[Swift] LeetCode - 39. Combination Sum (0) | 2022.02.16 |
[Swift] LeetCode - 17. Letter Combinations of a Phone Number (0) | 2022.02.16 |
[Swift] LeetCode - 200. Number of Islands (0) | 2022.02.16 |
댓글