a***e 发帖数: 413 | 1 为什么要j>=prevSize?总是不理解这一点,多谢!
if (i==0||S[i]!=S[i-1]||j>=prevSize)
https://oj.leetcode.com/problems/subsets-ii/
Given a collection of integers that might contain duplicates, S, return all
possible subsets.
Note:
vector > subsetsWithDup(vector &S) {
vector> ret;
int n = S.size();
if (n==0) return ret;
sort(S.begin(),S.end());
ret.resize(1);
int prevSize = 0;
for (int i=0; i
{
int retSize = ret.size();
for(int j=0; j
{
if (i==0||S[i]!=S[i-1]||j>=prevSize)
{
ret.push_back(ret[j]);
ret.back().push_back(S[i]);
}
}
prevSize = retSize;
}
} |
|