Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- func combinationSum3(_ k: Int, _ n: Int) -> [[Int]] {
- var res = [[Int]]()
- var list = [Int]()
- combination(k, 1, n, &list, &res)
- return res
- }
- func combination(_ count:Int, _ start:Int, _ remain: Int, _ list : inout [Int], _ res:inout [[Int]]){
- if list.count == count {
- if remain == 0 {
- res.append(list)
- }
- return
- }
- for i in stride(from: start, to: 10, by: 1){
- list.append(i)
- combination(count, i + 1, remain - i, &list, &res)
- list.removeLast()
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement