```
class Solution:
# @param num, a list of integer
# @return a list of lists of integer
def subsetsWithDup(self, S):
result = [[]]
S.sort()
def sub(prev, cur, result):
if cur == []:
return
for i in range(len(cur)):
if i == 0 or cur[i] != cur[i-1]:
now = prev+[cur[i]]
result.append(now)
sub(now, cur[i+1:], result)
sub([], S, result)
return result
```

I think this solution is quite straightforward.