利用好C++标准库,很好解决

字符串的排列

http://www.nowcoder.com/questionTerminal/fe6b651b66ae47d7acce78ffdd9a96c7

class Solution {
public:
    vector<string> Permutation(string str) {
        if (str.empty()) return {};
        sort(str.begin(), str.end());
        vector<string> ans;
        ans.push_back(str);
        while (next_permutation(str.begin(), str.end()))
            ans.push_back(str);
        return ans;
    }
};
全部评论
秀了,你出去吧,有请下一位面试者
2 回复 分享
发布于 2020-10-21 19:48
这个是开挂吧。。面试的时候肯定不能用这种
1 回复 分享
发布于 2020-08-26 15:33
请问如何去重复呢
点赞 回复 分享
发布于 2020-09-12 16:27
想请问您,next_permutation()函数对于字符串中有重复字符的情况适用吗?
点赞 回复 分享
发布于 2020-02-11 19:10

相关推荐

2025-12-28 22:19
门头沟学院 Java
不敢追165女神:简历写得毫无特点,你说你要是大二或者大三找寒假实习到暑期实习这段时间,你的简历还能约到面试。但是你是研究生哥,面试官不会因为你是研究生而降低要求,反而会觉得你是研究生才学了这么一点?为什么我不找个同阶段的本科生?
简历中的项目经历要怎么写
点赞 评论 收藏
分享
评论
41
3
分享

创作者周榜

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