当前位置:网站首页>78. 子集
78. 子集
2022-07-26 03:09:00 【Chenchen-】
给你一个整数数组 nums ,数组中的元素 互不相同 。返回该数组所有可能的子集(幂集)。
解集 不能 包含重复的子集。你可以按 任意顺序 返回解集。
示例 1:
输入:nums = [1,2,3]
输出:[[],[1],[2],[1,2],[3],[1,3],[2,3],[1,2,3]]
示例 2:
输入:nums = [0]
输出:[[],[0]]
提示:
1 <= nums.length <= 10
-10 <= nums[i] <= 10
nums 中的所有元素 互不相同
来源:力扣(LeetCode)
链接:https://leetcode.cn/problems/subsets
著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。
class Solution {
List<Integer> t = new ArrayList<Integer>();
List<List<Integer>> ans = new ArrayList<List<Integer>>();
public List<List<Integer>> subsets(int[] nums) {
int n = nums.length;
for (int mask = 0; mask < (1 << n); ++mask) {
t.clear();
for (int i = 0; i < n; ++i) {
if ((mask & (1 << i)) != 0) {
t.add(nums[i]);
}
}
ans.add(new ArrayList<Integer>(t));
}
return ans;
}
}边栏推荐
- Opencv 以指定格式保存图片
- Dataframe sorting: datetime format splitting; Delete a specific line; Group integration.
- 实现一个方法,找出数组中的第k大和第m大的数字相加之和
- Wechat official account mutual aid, open white groups, and small white newspaper groups to keep warm
- Longest Substring Without Repeating Characters
- [translation] announce Vites 13
- Self-supervised learning method to solve the inverse problem of Fokker-Planck Equation
- (九)属性自省
- Parallelloopbody in opencv
- Detailed explanation of extended physics informedneural networks paper
猜你喜欢

How to reinstall win7 system?

Have you ever seen this kind of dynamic programming -- the stock problem of state machine dynamic programming (Part 1)

Parallelloopbody in opencv

How to correctly calculate the CPU utilization of kubernetes container

中国信通院陈屹力:降本增效是企业云原生应用的最大价值

Functions and usage of snownlp Library

在混合云中管理数据库:八个关键注意事项

canvas——绘制曲线——挂钟,饼图,五角星

Execution process behind shell commands

LeetCode·
随机推荐
Study notes of pytorch deep learning practice: convolutional neural network (Advanced)
File operation (I) -- File introduction and file opening and closing methods
canvas——绘制图片——动图制作
Service gateway (zuul)
CMD CPM command summary
Teach you to rely on management hand in hand
Machine learning foundation plan 0-2: what is machine learning? What does it have to do with AI?
【尤里复裂人】带你轻松理解——深拷贝和浅拷贝
snownlp库各功能及用法
canvas——矩形的绘制——柱状图的制作
The source of everything, the choice of code branching strategy
Design of golang lottery system
一切的源头,代码分支策略的选择
[C Advanced] deeply explore the storage of data (in-depth analysis + interpretation of typical examples)
Usage of '...' in golang
[sql] case expression
VR panoramic shooting and production of business center helps businesses effectively attract people
Multithreaded programming
Safety margin of mass consumption
Autojs cloud control source code + display