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

字符串的全部子序列

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

class Solution {
public:
    string path;
    unordered_set<string>set;//去重
    vector<string>ans;
    int n;
    void f(string s,int dep){
        if(dep==n){
            set.insert(path);
            return;
        }
        path.push_back(s[dep]);
        f(s,dep+1);
        path.pop_back();//恢复现场
        f(s,dep+1);
    }
    vector<string> generatePermutation(string s) {
        n=s.size();
        f(s,0);
        for(string path:set){
            ans.push_back(path);
        }
        return ans;
    }
};

第1题【算法讲解038【必备】常见经典递归过程解析】 https://www.bilibili.com/video/BV19m4y1n7mo/?share_source=copy_web&vd_source=5065fa61022691e8df35c771a30e6d29

全部评论

相关推荐

头像
04-17 09:29
已编辑
湖南农业大学 后端
睡姿决定发型丫:本硕末9也是0offer,简历挂了挺多,只有淘天 美团 中兴给了面试机会,淘天二面挂,美团一面kpi面,中兴一面感觉也大概率kpi(虽然国企,但一面0技术纯聊天有点离谱吧)
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务