Saturday, October 4, 2014

Permutations

Problem

Given a collection of numbers, return all possible permutations.

For example,
[1,2,3] have the following permutations:
[1,2,3], [1,3,2], [2,1,3], [2,3,1], [3,1,2], and [3,2,1].

Idea

dfs, 依次处理num[]的每一个,递归的时候先检查num[i]是不是已经出现过了,如果没有然后插入.
  • How to find an element in vector

  • Solution


    No comments:

    Post a Comment