Skip to content

Instantly share code, notes, and snippets.

@sonyakc
sonyakc / Permutation.java
Created December 30, 2018 16:25
Output all permutations of a given string
import java.util.LinkedHashSet;
import java.util.Set;
public class Permutation {
public static void main(String[] args) {
String str = "sonya"; // 5 * 4 * 3 * 2 = 20 * 6 = 120
Permutation permutation = new Permutation();
StringBuilder builder = new StringBuilder();
Set<String> permSet = new LinkedHashSet<>();
permutation.permute(str, builder, permSet);