剑指offer 字符串的排列
来源:互联网 发布:java内部类例子 编辑:程序博客网 时间:2024/05/29 04:44
class Solution {public:vector<string> Permutation(string str) {sort(str.begin(), str.end());string tem = str;vector<string> ans;while (tem != "") {ans.push_back(tem);getnext(tem);}return ans;}void getnext(string &str) {int len = str.size();int i;int judge = 0;int cur = len - 2;while (cur >= 0) {for (i = len - 1; i > cur; i--) {if (str[i] > str[cur]) {judge = 1;break;}}if (judge) {swap(str[i], str[cur]);reverse(str.begin() + cur + 1, str.end());break;}cur--;}if (!judge)str = "";}};
运用了求一个排列的下一个排列算法,可以用递归,更加简单。
0 0
- 【剑指offer】字符串的排列
- 剑指offer--字符串的排列
- 《剑指offer》字符串的排列
- 【剑指Offer】字符串的排列
- 剑指offer--字符串的排列
- 剑指offer:字符串的排列
- 剑指offer:字符串的排列
- 剑指offer:字符串的排列
- [剑指offer]字符串的排列
- 《剑指offer》-字符串的排列
- 剑指offer|字符串的排列
- 【剑指offer】字符串的排列
- 《剑指offer》字符串的排列
- 剑指Offer:字符串的排列
- 【剑指offer】字符串的排列
- 剑指offer-字符串的排列
- 剑指offer 字符串的排列
- 剑指offer 字符串的排列
- Spring自动装配(注解)
- python2 和 python3比较
- 图片存储与转换处理
- 黑白棋游戏
- Generative Adversarial Nets
- 剑指offer 字符串的排列
- nyoj 915 -+字符串
- Oracle_PL/SQL 存储过程
- 因子平方和
- 64. Minimum Path Sum
- 解决"Classpath entry org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER will not be exported or published"问题
- 程序员的沟通之痛
- mysql 导出数据库到本地
- 个人记录-LeetCode 91. Decode Ways