Swift, the simple solution


  • 0
    C
    class Solution {
        func subsets(nums: [Int]) -> [[Int]] {
            if nums.count < 1 {
                return [nums]
            }
            
            var subsets:[[Int]] = []
            for num in nums {
                for var subNums in subsets {
                    subNums.append(num)
                    subsets.append(subNums)
                }
                subsets.append([num])
            }
            
            subsets.append([])
            
            return subsets
        }
    }

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.