class Solution { public $result; /** * @param Integer[] $nums * @return Integer[][] */ function subsets($nums) { $this->dfs($nums,0,[]); return $this->result; } function dfs($nums, $start, $path) { $this->result[] = $path; for ($i = $start, $iMax = count($nums); $i < $iMax; $i++) { $path[] = $nums[$i]; $this->dfs($nums, $i + 1, $path); array_pop($path); } } }
copy success
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23