My solution,but i don't understand very well


  • 0
    L
    public class Solution {
    	private List<List<Integer>> result = new ArrayList<List<Integer>>();
    	
        public List<List<Integer>> combine(int n, int k) {
        	List<Integer> cur = new ArrayList<Integer>();
        	
        	getResult(cur, 1, 0, k, n);
           
        	return result;
        }
        public void getResult(List<Integer> cur, int start, int dep, int depMax, int end){
        	if(dep == depMax){
        		List<Integer> temp = new ArrayList<Integer>(cur);
        		result.add(temp);
        	}else{
        		for(int i = start; i <= end; i++){
        			cur.add(i);
        			getResult(cur, i + 1, dep + 1, depMax, end);
        			cur.remove(cur.size() - 1);
        		}
        	}
        }
    }

Log in to reply
 

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