Swift for loop, super easy to follow with O(n^2) time O(1) space


  • 0
    Z
    class Solution {
        func subsets(_ nums: [Int]) -> [[Int]] {
            var result: [[Int]] = [[]]
            for i in nums {
                for r in result {
                    var temp = r
                    temp.append(i)
                    result.append(temp)
                }
            }
            return result
        }
    }
    

Log in to reply
 

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