题解 | #字符串的排列#

字符串的排列

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

方法之一next_permutation
CPP提供了内置函数next_permutation实现全排列,但需要对原数组进行排序。

class Solution {
public:
    vector Permutation(string str) {
        string path;
        vector res;
        sort(str.begin(), str.end());
        do{
            for(int i = 0; i < str.size(); i++){
                path += str[i];
            }
            res.emplace_back(path);
            path.erase(path.begin(), path.end());
        }while(next_permutation(str.begin(), str.end()));
        return res;
    }
};
全部评论

相关推荐

11-04 19:05
已编辑
东莞城市学院 单片机
不知道怎么取名字_:你这个要实习两年?哪有这么久的,感觉就是即使你毕业了,但还按实习的话,是不是不用给你缴社保公积金啥的
点赞 评论 收藏
分享
野猪不是猪🐗:还是太卑微了,什么叫放弃本次面试应该说经过评估,贵公司与自己不匹配,决定不再推进后续流程
点赞 评论 收藏
分享
评论
2
收藏
分享

创作者周榜

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