题目意思:全排列

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

  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. -_-#【CSS3】浏览器前缀

    前缀 浏览器 -khtml Konqueror(非常老的 Safari) -moz Firefox -o Opera -ms Internet Explorer -webkit Safari.Chro ...

  2. session与cookie的区别【转】

    我所知道的有以下区别:       1.session保存在服务器,客户端不知道其中的信息:cookie保存在客户端,服务器能够知道其中的信息.       2.session中保存的是对象,cook ...

  3. 【转】Android低功耗蓝牙应用开发获取的服务UUID

    原文网址:http://blog.csdn.net/zhangjs0322/article/details/39048939 Android低功耗蓝牙应用程序开始时获取到的蓝牙血压计所有服务的UUID ...

  4. Ubuntu 12.04 使用Eclipse搭建C/C++编译环境

    首先是安装Eclipse,方法有两种:       第一种是通过Ubuntu自带的程序安装功能安装Eclipse,应用程序->Ubtuntu软件中心,搜Eclipse安装即可.       第二 ...

  5. 动态规划(斜率优化):BZOJ 3675 [Apio2014]序列分割

    Description 小H最近迷上了一个分割序列的游戏.在这个游戏里,小H需要将一个长度为N的非负整数序列分割成k+l个非空的子序列.为了得到k+l个子序列, 小H将重复进行七次以下的步骤: 1.小 ...

  6. 后缀数组:SPOJ SUBST1 - New Distinct Substrings

    Given a string, we need to find the total number of its distinct substrings. Input T- number of test ...

  7. 如何在不影响数据库的正常使用的情况下得到数据的完整.mdf和.ldf文

    一:完整备份数据库 二:还原数据库 四:分离数据库即可得到.mdf和.ldf文件

  8. 数学概念——J - 数论,质因数分解

    J - 数论,质因数分解 Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit ...

  9. Away3D 4.1.4 中实现骨骼绑定

    骨骼的绑定归根结底就是将目标骨骼的位置以及旋转数据,同步给要绑定的显示对象. 先来看BindingTag.as package away3d.entities {     import away3d. ...

  10. [Angular 2] Validation

    Define a filed should has validation: export class DemoFormSku { myForm: ControlGroup; sku: Abstract ...