标签:obj not c++ oss contain class res void nbsp
class Solution { public: void dfs(vector<int> nums,int index,vector<int>&tmp,vector<vector<int>>&res){ res.push_back(tmp); if(index==nums.size()) return; for(int i=index;i<nums.size();i++){ tmp.push_back(nums[i]); dfs(nums,i+1,tmp,res); tmp.pop_back(); } } vector<vector<int>> subsets(vector<int>& nums) { vector<int>tmp; vector<vector<int>>res; dfs(nums,0,tmp,res); return res; } };
Python:
class Solution(object): def dfs(self,nums,res,tmp,index): res.append(tmp) if index==len(nums): return for i in range(index,len(nums)): self.dfs(nums,res,tmp+[nums[i]],i+1) def subsets(self, nums): """ :type nums: List[int] :rtype: List[List[int]] """ if not nums: return None res=[] tmp=[] self.dfs(nums,res,tmp,0) return res
标签:obj not c++ oss contain class res void nbsp
原文地址:https://www.cnblogs.com/xiaobaituyun/p/10645116.html