Untitled

mail@pastecode.io avatar
unknown
plain_text
2 months ago
653 B
6
Indexable
Never
class Solution {
    public List<List<Integer>> subsetsWithDup(int[] nums) {
        int n=nums.length;
        int p=1<<n;
        ArrayList<List<Integer>> ans=new ArrayList<>();
        for(int i=0;i<p;i++){
            ArrayList<Integer> l=new ArrayList<>();
            for(int j=0;j<nums.length;j++){
                if(checkBit(i,j)){
                    l.add(nums[j]);
                }
            }
            if(!ans.contains(l)){
                ans.add(l);
            }
        }
        return ans;
    }
    public boolean checkBit(int i,int j){
        if(((i>>j)&1)==1) return true;
        return false;
    }
}
Leave a Comment