import java.util.ArrayList; import java.util.HashSet; public class Solution { public ArrayList<String> Permutation(String str) { ArrayList<String> result = new ArrayList<String>(); if(str.length()<=0) return result; result = f(str); return result; } public ArrayList<String> f(String str) { ArrayList<String> s = new ArrayList<String>(); HashSet<Character> set = new HashSet<Character>(); for(int i=0;i<str.length();i++) { char first = str.charAt(i); if(!set.contains(first)) { set.add(first); if(str.length()>1) { StringBuilder next = new StringBuilder(str); String nextString = next.deleteCharAt(i).toString(); for(String ss:f(nextString)) s.add(first+ss); } else { s.add(String.valueOf(first)); } } } return s; } }