verry clean code


  • 0
    L
        public List<List<Integer>> subsets(int[] nums) {
            List<List<Integer>> res = new ArrayList<>();
    		List<Integer> subList = new ArrayList<>();
    		// 到数组的第i 个元素可产生的数据
    		res.add(new ArrayList<>());
    		for(int i = 0; i < nums.length; i++) {
    			int len = res.size();
    			for(int j = 0; j <len; j++) {
    				
    				subList = res.get(j);
    				
    				List<Integer> addList = new ArrayList<>();
    				for(int x :subList) {
    					addList.add(x);
    				}
    				addList.add(nums[i]);
    				res.add(addList);
    			}
    		}
    		return res;
        }
    }
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.