题目意思:全排列

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

  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. 图论(网络流,分数规划):COGS 2047. [ZOJ2676]网络战争

    2047. [ZOJ2676]网络战争 ★★★   输入文件:networkwar.in   输出文件:networkwar.out   评测插件 时间限制:5 s   内存限制:32 MB [题目描 ...

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

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

  3. delphi NativeXml的中文支持 乱码

    一般XML的编码格式设置成UTF8比较通用,下面演示使用UTF8编码方式存储和处理包含中文的XML字符串(文件).1.设置启用内置的widestring支持 NativeXml内部使用ANSI str ...

  4. 获取Android设备屏幕分辨率

    1.Android 4.3引入的wm工具: a.获取Android设备屏幕分辨率: adb shell wm size b.获取android设备屏幕密度: adb shell wm density ...

  5. artTemplate的使用总结

    原生语法 使用原生语法,需要导入template-native.js文件. 在HTML中定义模板,注意模板的位置,不要放到被渲染区域,防止模板丢失. <script id="main_ ...

  6. 原生 JavaScript 代码和Jquery实现对比

    下面就带大家一起看看在 IE 浏览器环境中如果使用原生 JavaScript 代码实现 jQuery 中的功能.如果你打算自己开发一个小的基础框架,可以好好参考一下这些代码的实现. 本文转载:http ...

  7. 汉诺塔III 递推题

    题目描述: 约19世纪末,在欧州的商店中出售一种智力玩具,在一块铜板上有三根杆,最左边的杆上自上而下.由小到大顺序串着由64个圆盘构成的塔.目的是将最左边杆上的盘全部移到右边的杆上,条件是一次只能移动 ...

  8. C#“简单加密文本器”的实现

    本示例只能加密英文文本,使用的算法为异或算法.源代码:http://pan.baidu.com/share/link?shareid=3241348313&uk=1761850335(本示例属 ...

  9. gridview添加header

    gridview是不能添加header的,这里的解决方法是将listview改造成gridview使用,功能很好用,唯一的缺点是列数不能自适应 示例代码下载地址http://pan.baidu.com ...

  10. RHEL7下PXE+Apache+Kickstart无人值守安装操作系统

    RHEL7下PXE+Apache+Kickstart无人值守安装操作系统 1.配置yum源 vim /etc/yum.repos.d/development.repo [development] na ...