Problem Description

Given an integer array nums of unique elements, return all possible subsets (the power set).

The solution set must not contain duplicate subsets. Return the solution in any order.

Examples

Example 1:

Input: nums = [1,2,3]
Output: [[],[1],[2],[1,2],[3],[1,3],[2,3],[1,2,3]]

Example 2:

Input: nums = [0]
Output: [[],[0]]

Constraints:

解析

題目給定一組整數陣列 nums ,

求寫出一個演算法來推算出所有可能的陣列子集合

對於每個元素都為可選或可不選

假設有 n 個元素,就有 $2^n$ 個子集合

如下圖:

backtracking.drawio.png