public List
> combinationSum3(int k, int n) { List
> res = new ArrayList
>(); List item = new ArrayList (); int sum[] = {0}; dfs(k, n, res, item, 1, sum); return res; } public void dfs(int k, int n, List
> res, List item, int depth, int[] sum) { if (item.size() > k || sum[0] > n) return; if (item.size() == k && sum[0] == n) { res.add(new ArrayList (item)); return; } for (int i = depth; i <=9; i++) { item.add(i); sum[0] += i; dfs(k, n, res, item, i+1, sum); item.remove(item.size() - 1); sum[0] -= i; } }