* @Author: Goog Tech
* @Date: 2020-10-27 14:18:51
* @LastEditTime: 2020-10-27 14:24:07
* @Description: https://leetcode-cn.com/problems/subsets/
* @FilePath: \leetcode-googtech\#78. Subsets\Solution.java
* @WebSite: https://algorithm.show/
* @Reference: https://leetcode-cn.com/problems/subsets/solution/hui-su-wei-yun-suan-di-gui-deng-gong-4chong-fang-s/
*/
class Solution {
public List<List<Integer>> subsets(int[] nums) {
List<List<Integer>> result = new ArrayList<>();
result.add(new ArrayList<>());
for(int i = 0; i < nums.length; i++) {
int all = result.size();
for(int j = 0; j < all; j++) {
List<Integer> temp = new ArrayList<>(result.get(j));
temp.add(nums[i]);
result.add(temp);
}
}
return result;
}
}
'''
Author: Goog Tech
Date: 2020-10-27 14:18:56
LastEditTime: 2020-10-27 14:20:21
Description: https://leetcode-cn.com/problems/subsets/
FilePath: \leetcode-googtech\#78. Subsets\Solution.py
WebSite: https://algorithm.show/
'''
class Solution(object):
def subsets(self, nums):
"""
:type nums: List[int]
:rtype: List[List[int]]
"""
result = [[]]
for i in nums:
result = result + [[i] + num for num in result]
return result