backTrack($nums, 0, []); return $this->result; } function backTrack($nums, $step, $path, $is_choose_pre = false) { if($step === count($nums)){ $this->result[] = $path; return; } $this->backTrack($nums, $step + 1, $path); if(!$is_choose_pre && $step > 0 && $nums[$step] == $nums[$step - 1]){ return; } $path[] = $nums[$step]; $this->backTrack($nums, $step + 1, $path, true); unset($path[count($path) - 1]); } } $model = new Solution(); var_dump($model->subsetsWithDup([1, 2, 2]));