当前位置:网站首页>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]);
}
}
};
边栏推荐
猜你喜欢
【二开】【JeecgBoot】修改分页参数
Video based full link Intelligent Cloud? This article explains in detail what Alibaba cloud video cloud "intelligent media production" is
Wallys/IPQ6010 (IPQ6018 FAMILY) EMBEDDED BOARD WITH ON-BOARD WIFI DUAL BAND DUAL CONCURRENT
Use of JSON extractor originals in JMeter
ISP、IAP、ICP、JTAG、SWD的编程特点
How to cancel automatic saving of changes in sqlyog database
虚数j的物理意义
[higherhrnet] higherhrnet detailed heat map regression code of higherhrnet
ORM -- logical relation and & or; Sort operation, update record operation, delete record operation
IO模型复习
随机推荐
ORM模型--数据记录的创建操作,查询操作
Chris LATTNER, the father of llvm: why should we rebuild AI infrastructure software
The request object parses the request body and request header parameters
Postman interface test VII
Web3.0 series distributed storage IPFs
Google Colab装载Google Drive(Google Colab中使用Google Drive)
Postman interface test IV
The new activity of "the arrival of twelve constellations and goddesses" was launched
STM32 ADC和DMA
学习记录——高精度加法和乘法
Word自动生成目录的方法
Use of JSON extractor originals in JMeter
Finally, there is no need to change a line of code! Shardingsphere native driver comes out
Interface test
Programming features of ISP, IAP, ICP, JTAG and SWD
A wave of open source notebooks is coming
Deadlock caused by non clustered index in SQL Server
[learning notes - Li Hongyi] Gan (generation of confrontation network) full series (I)
Some thoughts on the testing work in the process of R & D
ORM model -- associated fields, abstract model classes