题解 | #字符串的全部子序列#

字符串的全部子序列

https://www.nowcoder.com/practice/92e6247998294f2c933906fdedbc6e6a

class Solution {
public:
    /**
     * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
     *
     * 
     * @param s string字符串 
     * @return string字符串vector
     */
    vector<string> generatePermutation(string s) {
        unordered_set<string> set;
        vector<char> path(s.length());
        f2(s, 0, path, 0, set);
        return vector<string>(set.begin(), set.end());
    }

private:
    static void f2(const string& s, int i, vector<char>& path, int size, unordered_set<string>& set) {
        if (i == s.length()) {
            set.insert(string(path.begin(), path.begin() + size));
        } else {
            path[size] = s[i]; // Include current character
            f2(s, i + 1, path, size + 1, set); // Recur with the current character included
            f2(s, i + 1, path, size, set);     // Recur without the current character
        }
    }
};

全部评论

相关推荐

投递长鑫存储等公司8个岗位
点赞 评论 收藏
分享
牛客38347925...:9,2学生暑期实习失利开始投小厂,给这群人整自信了
点赞 评论 收藏
分享
05-25 10:45
门头沟学院 Java
Frank_zhan...:没实习一个项目肯定不够,可以再做一个轮子,技术栈再补一个mq,微服务,整体再换个简历模板,暑期尽量再找一个日常实习
无实习如何秋招上岸
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务