Home > Back-end >  Subset - leetcode topics
Subset - leetcode topics

Time:10-15

Given a set of nums without repeating element integer array, returns the array of all possible subsets (power set),

Description: a subset of the solution set can not contain duplicate,

Example:

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

[3],
[1],
[2],
[1, 2, 3],
[1, 3],
[2, 3],
[1, 2],
[]
]

CodePudding user response:

The class Solution {
Public:
Vector Subsets (vector & Nums) {
Vector Res.
Vector The path;
Int start=0;
Backtrace (res, path, start, nums);
return res;
}
Void backtrace (vector & Res, vector & Path, int start, vector Nums) {
Res. The push_back (path);
For (int I=start; iPath. The push_back (nums [I]);
Backtrace (res, path, I + 1, nums);
Path. Pop_back ();
}
}
};
I put the back of the bottom fifth sentences into a backtrace (res, path, start + 1, nums); Why the result is not the same!

  • Related