Combinations

Given two integers n and k, return all possible combinations of k numbers out of 1 ... n.

Solution:

Simply using recursion. Use a vector called prefix to generate the combination of numbers.

The following code passes the LeetCode Online Large Judge.

Comments

Popular posts from this blog

House Robber

Binary Tree Maximum Path Sum

[ITint5] Maximum Subarray for a Circular Array