Generating all permutations of a given string(JAVA)
来源:互联网 发布:实用数据再分析法 pdf 编辑:程序博客网 时间:2024/06/01 21:23
What is an elegant way to find all the permutations of a string. E.g.ba
, would be ba
and ab
, but what about abcdefgh
? Is there any example Java implementation?
The answer below is obviously elegant!
public static void permutation(String str) { permutation("", str); }private static void permutation(String prefix, String str) { int n = str.length(); if (n == 0) System.out.println(prefix); else { for (int i = 0; i < n; i++) permutation(prefix + str.charAt(i), str.substring(0, i) + str.substring(i+1, n)); }}
Reference: http://stackoverflow.com/questions/4240080/generating-all-permutations-of-a-given-string
1 0
- Generating all permutations of a given string(JAVA)
- Write a C program to print all permutations of a given string
- Write a program to print all permutations of a given string
- Write a method to compute all permutations of a string
- Given a collection of distinct numbers, return all possible permutations.排列组合
- Permutations of a String
- Q9.5 Write a method to compute all permutations of a string
- All factors of a given number
- [LeetCode] Permutations (Find all permutations of a integer array w/ or w/o duplicates)
- find all the permutation of a string
- print all permutation of a string(recursion)
- get all Palindromes of a string
- [hackerrank Value of all Permutations]
- ch8-4: find the permutations of a string
- Given n pairs of parentheses, write a function to generate all combinations of well-formed parenthe
- Write a method that counts the number of occurrences of a given character in a string
- Given a sequence of numbers (or array).Find the maximum distance between all the same numbers.
- CareerCup Find all the conflicting appointments from a given list of n appointments.
- C++ STL--stack/queue 的使用方法
- 史上最全 Android 面试资料集合
- 下载过程中修改文件名
- Oracle删除数据如何恢复数据
- 什么是NoSql
- Generating all permutations of a given string(JAVA)
- 无刷新提交表单(php+js+ajax简单实例 )
- bzoj 3144: [Hnoi2013]切糕(最小割)
- crypto-js,require,nodejs,加密使用手册
- C++ char*,const char*,string的相互转换
- Java JDBC事务与JTA分布式事务
- 性能优化(一):迭代DOM真的很慢吗?
- el表达式的function标签
- JAVA的节点流和处理流以及流的关闭顺序