字符串全排列
来源:互联网 发布:知乎平均985 编辑:程序博客网 时间:2024/06/13 20:22
题目描述
输入一个字符串,按字典序打印出该字符串中字符的所有排列。例如输入字符串abc,则打印出由字符a,b,c所能排列出来的所有字符串abc,acb,bac,bca,cab和cba。
输入描述:
输入一个字符串,长度不超过9(可能有字符重复),字符只包括大小写字母。
#include <algorithm>class Solution {public: vector<string> result_final; set<string> result; void permRec(string str, int i){ if(i >= str.length()){ return; } if(i == str.length() - 1) { result.insert(str); return; } else { for(int j = i; j < str.length(); j++){ //if(str[i] != str[j]){ char tmp = str[i]; str[i] = str[j]; str[j] = tmp; permRec(str, i + 1); tmp = str[i]; str[i] = str[j]; str[j] = tmp; //} } } } vector<string> Permutation(string str) {//sort(str.begin(), str.end()); permRec(str, 0); for(set<string>::iterator it = result.begin(); it != result.end(); it++){ result_final.push_back(*it); } //sort(result.begin(), result.end()); return result_final; }};
阅读全文
0 0
- 字符串的全排列
- 字符串的全排列
- 字符串全排列问题
- 字符串全排列
- 字符串全排列问题
- 字符串全排列
- 求字符串全排列
- 求字符串全排列
- 字符串的全排列
- 字符串全排列代码
- 字符串全排列
- 字符串全排列
- 字符串全排列
- 字符串的全排列
- 字符串全排列
- 求字符串全排列
- 字符串全排列
- 字符串的全排列
- nginx-config
- 卷积神经网络——ResNeXt
- 【python】yield用法入门
- Specific cuDNN installation
- 英语单词
- 字符串全排列
- 演练:开发预测分析解决方案,用于在 Azure 机器学习中评估信用风险
- 无名namespace
- codeforces 413E 线段树
- golang chanel
- ERROR Dispatcher:42
- spring学习笔记 —— spring概述
- 搭建PHP开发环境(五)-虚拟主机
- HDU 1525 Euclid's Game 找规律博弈