For Subsets I we already have one:
https://oj.leetcode.com/discuss/9213/my-solution-using-bit-manipulation
I'm wondering how to come up with a similar solution for Subsets II. Can anyone help?
For Subsets I we already have one:
https://oj.leetcode.com/discuss/9213/my-solution-using-bit-manipulation
I'm wondering how to come up with a similar solution for Subsets II. Can anyone help?
We can also declare two paras indicating the last value and the bit value of last value.
For example:
lastvalue and lastbitvalue
lst = [1,2,2,3]
so "1101" is valid,
"1011" is not valid because it is the same as "1101"
the additional judgement comparing with Subsets I is :(in Python)
if S[j] == lastvalue and lastbitvalue == 0 and i & (1<<j):
#clear the list to be appended to return list which is constructed in the previous loop
#break and return to the loop of i
If you use bit manipulation in Subsets I, you can understand i and j easily.