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

Maximum Gap

[ITint5] Maximum Subarray for a Circular Array

[CC150] Chapter 8 Object-Oriented Design