Here you can find the source of findAllSubsequences(String str)
Parameter | Description |
---|---|
str | a parameter |
public static Set<String> findAllSubsequences(String str)
//package com.java2s; //License from project: Open Source License import java.util.*; public class Main { /**//from w w w .j av a 2s. c o m * * @param str * @return */ public static Set<String> findAllSubsequences(String str) { if (str.equals("")) { Set<String> subsequences = new HashSet<>(); subsequences.add(str); return subsequences; } Set<String> subsequences = new HashSet<>(); char current = str.charAt(0); str = new StringBuilder(str).deleteCharAt(0).toString(); Set<String> childSubsequences = findAllSubsequences(str); for (String subsequence : childSubsequences) { StringBuilder newSequence = new StringBuilder(); newSequence.append(current); newSequence.append(subsequence); subsequences.add(newSequence.toString()); } subsequences.addAll(childSubsequences); return subsequences; } }