public class Solution{ public static List<String> subsequenceOfString(String s) { if (s == null || s.length() == 0) { return new LinkedList<>(); } Set<String> set = new HashSet<>(); helper(s, set, new StringBuilder(), 0); List<String> res = new LinkedList<>(set); return res; } public static void helper(String s, Set<String> res, StringBuilder sb, int pos) { if (sb.length() != 0) { res.add(sb.toString()); } for (int i = pos; i < s.length(); i++) { sb.append(s.charAt(i)); helper(s, res, sb, i + 1); sb.deleteCharAt(sb.length() - 1); } } public static void main(String[] args){ String s = "hello"; Solution sol = new Solution(); System.out.println(sol.subsequenceOfString(s)); } }