zoukankan      html  css  js  c++  java
  • leetcode104:permutations

    题目描述

    给出一组数字,返回该组数字的所有排列
    例如:
    [1,2,3]的所有排列如下
    [1,2,3],[1,3,2],[2,1,3],[2,3,1],[3,1,2], [3,2,1].
     (以数字在数组中的位置靠前为优先级,按字典序排列输出。)

     
    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].
    (Take the more front position of the number in the array as the priority, and arrange the output in dictionary order.)
     
    class Solution {
    public:
        vector<vector<int> > permute(vector<int> &num) {
            //next_permutation:会取得[first,last]所标识之序列的下一个排序组合
            //如果没有下一个排列组合,便返回false,否则返回true
            vector <vector<int>> res;
        sort(num.begin(),num.end());
            do {
                res.push_back(num);
                
            }while (next_permutation(num.begin(), num.end()));
          return res;
        }
    };
  • 相关阅读:
    linux随记
    springboot-2
    netty-lean1
    nginx
    自定义启动器
    arrayList add
    Mybatis 转义符
    idea 闪退 但是启动的服务还在解决办法
    java 通过map根据list某个字段进行合并
    java list的深拷贝
  • 原文地址:https://www.cnblogs.com/hrnn/p/13416320.html
Copyright © 2011-2022 走看看