leetcode78 子集
生活随笔
收集整理的這篇文章主要介紹了
leetcode78 子集
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
給定一組不含重復元素的整數數組?nums,返回該數組所有可能的子集(冪集)。
說明:解集不能包含重復的子集。
示例:
輸入: nums = [1,2,3]
輸出:
[
? [3],
??[1],
??[2],
??[1,2,3],
??[1,3],
??[2,3],
??[1,2],
??[]
]
思路:簡單搜索,思路見代碼。
class Solution {List<List<Integer>> lists = new ArrayList<>();public List<List<Integer>> subsets(int[] nums) {if(nums == null || nums.length ==0)return lists;List<Integer> list = new ArrayList<>();process(list, nums, 0);return lists;}private void process(List<Integer>list, int[] nums, int start){lists.add(new ArrayList(list));for(int i = start; i < nums.length; i++){list.add(nums[i]);process(list, nums, i+1);list.remove(list.size()-1);}} }?
總結
以上是生活随笔為你收集整理的leetcode78 子集的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: springboot1——spring相
- 下一篇: 为什么需要智能指针