全排列Permutations
描述
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]
代码
package com.lilei.myes.es.pack1107;
public class quanpailie {
public static void main(String[] args) {
char[] cs = new char[] { 'a', 'b', 'c','d' };
pailie(cs, 0);
}
public static void pailie(char[] cs, int e) {
if (e == cs.length) {
System.out.println(new String(cs));
} else {
for (int i = e; i < cs.length; i++) {
swap(cs, i, e);
pailie(cs, e + 1);
swap(cs, i, e);
}
}
}
static void swap(char[] cs, int a, int b) {
char tmp = cs[a];
cs[a] = cs[b];
cs[b] = tmp;
}
}
全排列Permutations的更多相关文章
- [Swift]LeetCode46. 全排列 | Permutations
Given a collection of distinct integers, return all possible permutations. Example: Input: [1,2,3] O ...
- [Leetcode 46]全排列 Permutations 递归
[题目] Given a collection of distinct integers, return all possible permutations. 数组的组合情况. Input: [1,2 ...
- 全排列 Permutations
class Solution { public: vector<vector<int>> permute(vector<int>& nums) { sort ...
- Swift LeetCode 目录 | Catalog
请点击页面左上角 -> Fork me on Github 或直接访问本项目Github地址:LeetCode Solution by Swift 说明:题目中含有$符号则为付费题目. 如 ...
- [LeetCode] Permutations II 全排列之二
Given a collection of numbers that might contain duplicates, return all possible unique permutations ...
- [LeetCode] Permutations 全排列
Given a collection of numbers, return all possible permutations. For example,[1,2,3] have the follow ...
- [CareerCup] 9.5 Permutations 全排列
9.5 Write a method to compute all permutations of a string. LeetCode上的原题,请参加我之前的博客Permutations 全排列和P ...
- lintcode 中等题:permutations 全排列
题目 全排列 给定一个数字列表,返回其所有可能的排列. 您在真实的面试中是否遇到过这个题? Yes 样例 给出一个列表[1,2,3],其全排列为: [ [1,2,3], [1,3,2], [2,1,3 ...
- leetcode Permutations II 无重全排列
作者:jostree 转载请注明出处 http://www.cnblogs.com/jostree/p/4051169.html 题目链接:leetcode Permutations II 无重全排 ...
随机推荐
- Python实战之Selenium自动化测试web刷新FW
需求:将手工登录,手工刷新服务器的FW转化为Python+Selenium实现自动化操作. 1.创建用户表,实现数据与脚本分离.需要读取模块. 2.自动化刷新FW. 不说话,直接上代码: 1userd ...
- vuejs2-生命周期
https://segmentfault.com/a/1190000008879966 1 声明周期图示 2 过渡
- 有趣的flash例子
仓鼠 <object type="application/x-shockwave-flash" data="http://cdn.abowman.com/widge ...
- DevOps之服务故障
唠叨话 关于德语噢屁事的知识点,仅提供精华汇总,具体知识点细节,参考教程网址,如需帮助,请留言. <DevOps服务故障> 0.故障1.设施故障2.设备故障3.系统故障4.虚拟化故障5.存 ...
- C#使用Xamarin开发可移植移动应用进阶篇(10.综合演练,来一份增删改查CRUD)
前言 系列目录 C#使用Xamarin开发可移植移动应用目录 源码地址:https://github.com/l2999019/DemoApp 可以Star一下,随意 - - 说点什么.. 呃 也有半 ...
- Unity Shader - 消融效果原理与变体
基本原理与实现 主要使用噪声和透明度测试,从噪声图中读取某个通道的值,然后使用该值进行透明度测试. 主要代码如下: fixed cutout = tex2D(_NoiseTex, i.uvNoiseT ...
- 使用vim编写hexo文档,并用ultisnips/snipmates/snippets插件补全
作为一个vim使用者,编写markdown文档时若不能用vim这怎么能受的了! 下面是我编写markdown的时候用到的插件 Plugin 'Markdown'Plugin 'Markdown-syn ...
- swiper使用小结
最近做一个移动端项目想用Swiper移动端插件,需求实现一个轮播图的效果,并且需要自定义分页器,效果跟这个差不多这里demo 好吧,开始动手! 注意参考的3.0Swiper的API文档需要引入3.0版 ...
- NandFlash ECC 校验
ECC的全称是Error Checking and Correction,是一种用于Nand的差错检测和修正算法.如果操作时序和电路稳定性不存在问题的话,NAND Flash出错的时候一般不会造成整个 ...
- memset和fill_n区别
1. 函数名: memset 所属头文件:<string.h> 用法:void *memset(void *s, char ch, unsigned n); 对于对int之类的数组,只能用 ...