本文共 588 字,大约阅读时间需要 1 分钟。
问题:
解答:
典型的深搜解决。
代码:
class Solution { public: vector> subsets(vector &S) { vector > res; vector temp; int n = S.size(); if (n == 0) return res; sort(S.begin(), S.end()); search(0, n, res, temp, S); return res; } void search(int k, int n, vector > &res, vector &temp, vector &S) { if (k == n) { res.push_back(temp); return; } temp.push_back(S[k]); search(k + 1, n, res, temp, S); temp.pop_back(); search(k + 1, n, res, temp, S); } };
转载地址:http://wytsi.baihongyu.com/