全排列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 无重全排 ...
随机推荐
- REST架构概述
REST概述 REST(英文:Representational State Transfer,简称REST)描述了一个架构样式的网络系统,比如 web 应用程序.它首次出现在 2000 年 Roy F ...
- DB2插入数据 sqlcode302 sqlstate22001错误如何解决?
总结:出现这种错误的原因主要是,插入数据时的长度和数据库中定义的长度不匹配或超出限制.
- struts2中的结果视图类型
实际上在Struts2框架中,一个完整的结果视图配置文件应该是: <action name="Action名称" class="Action类路径" me ...
- 网站常用的一些javascript封装 简化调用
//用于网页地址参数 //参数中包含出了英文中文数字之外的其他符号时进行编码并在前面加"=="进行标识,否则直接返回 //解码时根据是否含有"=="标识来决定是 ...
- 将 C# 枚举反序列化为 JSON 字符串 基础理论
该转换过程需要引用 Newtonsoft.JSON,这其中的转换过程还是蛮有意思的. 一.定义枚举 /// <summary> /// 托寄物品枚举 /// </summary> ...
- EasyUI DataGrid 基于 Ajax 自定义取值(loadData)
为 datagrid 加载数据分两种情况: 一种是基于 Ajax 请求获取数据然后通过"loadData"方法来赋值: 另一种是直接使用 datagrid 自带的"loa ...
- SAP 邮件发送
1.******************** *调用发送邮件函数 CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1' EXPORTING DOCUMENT_DA ...
- java基础---java语言概述
一.计算机编程的两种范型 1.面向过程的模型---具有线性执行特点,认为是代码作用于数据. 2.面向对象的模型---围绕它的数据(即对象)和为这个数据定义的接口来组织程序:实际上是用数据控制代码的访问 ...
- CSS样式之表格,表单
布局样式 .container:固定宽度并具响应式 .container-fluid自由宽度(100%宽度) 标题样式 <h1>到<h6> 样式已经写好了,可以直接用,兼容性也 ...
- HTML5-前端开发很火且工资很高?
前言 晚上逛论坛看到一篇对从事HTML5前端开发的文章写的非常不错,和目前的市场形势差不多,然后我在其基础上给大家进行加工总结一下分享给大家.今天我们谈论的话题是<<为什么从事HTML5前 ...