Question: https://oj.leetcode.com/problems/subsets/
Question Name: Subsets
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | class Solution: # @param S, a list of integer # @return a list of lists of integer def subsets(self, S): ''' A problem to test the bit operation. ''' S.sort() # Make sure the result is non-descending order. limit = 1 << len(S) current = 0 # In current, bit[i] == 1 means S[i] is chosen. result = [] while current < limit: # Construct the list for "current" temp = [] for index in xrange(len(S)): if (1 << index) & current != 0: temp.append(S[index]) result.append(temp) current += 1 return result |