求字符串的所有子序列

子序列包含空序列和满序列(自身)
一般子序列的个数由字符串长度的个数n决定。
个数:2的n次方

using System;
using System.Collections.Generic;

class Program
{
    static void Main()
    {
        string inputs = "abcdefg";
        List list = FindAllSequence(inputs);
        list.ForEach(x => Console.WriteLine(x));
        Console.ReadLine();
    }

    private static List FindAllSequence(string inputs)
    {
        var list = new List();
        FindSubSequence(inputs, "", 0, list);
        return list;
    }

    private static void FindSubSequence(string inputs, string currentSubSequence, int index, List list)
    {
        if (index.Equals(inputs.Length))
        {
            list.Add(currentSubSequence);
            //此处应该返回,否则会继续执行满足条件以外的代码,容易出现数组越界的问题
            return;
        }
        FindSubSequence(inputs, currentSubSequence + inputs[index], index + 1, l

你可能感兴趣的:(算法,windows,microsoft)