当前位置:网站首页>Sword finger offer 38 Arrangement of strings [no description written]
Sword finger offer 38 Arrangement of strings [no description written]
2022-07-07 10:22:00 【qq_ forty-two million one hundred and twenty thousand eight hun】
subject
Enter a string , Print out all the permutations of the characters in the string .
You can return this array of strings in any order , But there's no repetition in it .
Example
Input :s = “abc”
Output :[“abc”,“acb”,“bac”,“bca”,“cab”,“cba”]
C++ Realization
class Solution {
public:
vector<string> permutation(string s) {
dfs(s,0);
return ans;
}
private:
vector<string> ans;
void dfs(string s,int pos)
{
bool flag = true;
if(pos == s.size()-1)
{
ans.push_back(s);
return ;
}
set<int> st;// Used to store letters that have been used in the current position , Used for de pruning
for(int i = pos;i < s.size();++i)
{
if(st.find(s[i]) != st.end()) continue; // If the current letter has been used, skip , namely dfs Middle pruning operation
st.insert(s[i]);
swap(s[i],s[pos]);
dfs(s,pos+1);
swap(s[i],s[pos]);
}
}
};
边栏推荐
猜你喜欢

Postman interface test III

A wave of open source notebooks is coming

ISP、IAP、ICP、JTAG、SWD的编程特点

Chris Lattner, père de llvm: Pourquoi reconstruire le logiciel d'infrastructure ai

Serial communication relay Modbus communication host computer debugging software tool project development case

Remote meter reading, switching on and off operation command

SolidWorks工程图中添加中心线和中心符号线的办法

Google Colab装载Google Drive(Google Colab中使用Google Drive)

STM32基础知识—内存映射
![[higherhrnet] higherhrnet detailed heat map regression code of higherhrnet](/img/3c/890f2481231482645554f86dd614a9.png)
[higherhrnet] higherhrnet detailed heat map regression code of higherhrnet
随机推荐
电表远程抄表拉合闸操作命令指令
【acwing】786. Number k
[learning notes - Li Hongyi] Gan (generation of confrontation network) full series (I)
Google Colab装载Google Drive(Google Colab中使用Google Drive)
Bit operation ==c language 2
ORM--查询类型,关联查询
Advanced function learning in ES6
Bean operation domain and life cycle
ES类和对象、原型
Mongodb creates an implicit database as an exercise
Web3.0 series distributed storage IPFs
LLVM之父Chris Lattner:为什么我们要重建AI基础设施软件
搭建物联网硬件通信技术几种方案
MCU与MPU的区别
Introduction to energy Router: Architecture and functions for energy Internet
【acwing】789. Range of numbers (binary basis)
C#记录日志方法
ES6中的原型对象
Encrypt and decrypt stored procedures (SQL 2008/sql 2012)
Use of JSON extractor originals in JMeter