题目意思:全排列

思路:其实看这题目意思,是不太希望用递归的,不过还是用了递归,非递归的以后再搞吧

  ps:vector这玩意不能随便返回,开始递归方法用vector,直接到500ms,换成void,到12ms

 class Solution {
public:
vector<vector<int>> permute(vector<int>& nums) {
vector<vector<int> >ans;
permute1(ans,nums,);
return ans;
}
void permute1(vector<vector<int>>& ans,vector<int>& nums,int begin) {
if(begin==nums.size()-){
ans.push_back(nums);
}
for(int i=begin;i<nums.size();++i){
swap(nums[i],nums[begin]);
permute1(ans,nums,begin+);
swap(nums[i],nums[begin]);
}
}
};

46 Permutations(全排列Medium)的更多相关文章

  1. [LeetCode] 46. Permutations 全排列

    Given a collection of distinct integers, return all possible permutations. Example: Input: [1,2,3] O ...

  2. [leetcode]46. Permutations全排列(给定序列无重复元素)

    Given a collection of distinct integers, return all possible permutations. Input: [1,2,3] Output: [ ...

  3. 46. Permutations (全排列)

    Given a collection of distinct numbers, return all possible permutations. For example,[1,2,3] have t ...

  4. LeetCode:46. Permutations(Medium)

    1. 原题链接 https://leetcode.com/problems/permutations/description/ 2. 题目要求 给定一个整型数组nums,数组中的数字互不相同,返回该数 ...

  5. LeetCode - 46. Permutations

    46. Permutations Problem's Link -------------------------------------------------------------------- ...

  6. 刷题46. Permutations

    一.题目说明 题目是46. Permutations,给一组各不相同的数,求其所有的排列组合.难度是Medium 二.我的解答 这个题目,前面遇到过类似的.回溯法(树的深度优先算法),或者根据如下求解 ...

  7. [CareerCup] 9.5 Permutations 全排列

    9.5 Write a method to compute all permutations of a string. LeetCode上的原题,请参加我之前的博客Permutations 全排列和P ...

  8. [Leetcode][Python]46: Permutations

    # -*- coding: utf8 -*-'''__author__ = 'dabay.wang@gmail.com' 46: Permutationshttps://leetcode.com/pr ...

  9. 46. Permutations 排列数

    46. Permutations 题目 Given a collection of distinct numbers, return all possible permutations. For ex ...

随机推荐

  1. Codeforces 715B & 716D Complete The Graph 【最短路】 (Codeforces Round #372 (Div. 2))

    B. Complete The Graph time limit per test 4 seconds memory limit per test 256 megabytes input standa ...

  2. Merge Intervals——LeetCode

    Given a collection of intervals, merge all overlapping intervals. For example,Given [1,3],[2,6],[8,1 ...

  3. Count Primes ——LeetCode

    Description: Count the number of prime numbers less than a non-negative number, n. 题目大意:给一个int,返回小于它 ...

  4. 关于Linux

    这是一个2B让我写的关于Linux的一点东西. 其实我对Linux一直都是持有一种很尊敬的态度,作为一个非商业性的操作系统,能够成长成这样简直是不可思议,有一种Dota在游戏界的感觉,很让人佩服.但是 ...

  5. 如何修改WAMP中mysql数据库账号和密码

    WAMP安装好后,mysql密码是为空的,那么要如何修改呢?其实很简单,通过几条指令就行了,下面我就一步步来操作. 首先,通过WAMP打开mysql控制台. 提示输入密码,因为现在是空,所以直接按回车 ...

  6. SunTlsRsaPremasterSecret KeyGenerator not available问题解决

    本地Idea测试可以,部署到开发环境遇到下面的问题: javax.net.ssl.SSLKeyException: RSA premaster secret error at com.sun.net. ...

  7. Unity3d个人信息开发流程

    1.首先先对需要交互的属性进行G/S,比如声明金币的属性 private int _coin; public String Coin{ get{ return _coin; } set{ return ...

  8. Qt 学习之路 :进程间通信

    上一章我们了解了有关进程的基本知识.我们将进程理解为相互独立的正在运行的程序.由于二者是相互独立的,就存在交互的可能性,也就是我们所说的进程间通信(Inter-Process Communicatio ...

  9. mysql中数据库database、实例instance、会话session的关系

    1. No suitable driver found for http://127.0.0.1:3306/test jdbc_url错误,jdbc走自己的协议. 正确的路径应该是:jdbc:mysq ...

  10. C++笔试题库-------Coding整理

    1. 反转字符串 char* strrev1(const char* str) { int len = strlen(str); ]; char *p = temp + len; *p = '\0'; ...