当前位置:网站首页>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]);
}
}
};
边栏推荐
猜你喜欢

反卷积通俗详细解析与nn.ConvTranspose2d重要参数解释

Wallys/IPQ6010 (IPQ6018 FAMILY) EMBEDDED BOARD WITH ON-BOARD WIFI DUAL BAND DUAL CONCURRENT

Remote meter reading, switching on and off operation command

Web3.0 series distributed storage IPFs

柏拉图和他的三个弟子的故事:如何寻找幸福?如何寻找理想伴侣?
![[higherhrnet] higherhrnet detailed heat map regression code of higherhrnet](/img/3c/890f2481231482645554f86dd614a9.png)
[higherhrnet] higherhrnet detailed heat map regression code of higherhrnet

STM32 Basics - memory mapping

ArcGIS operation: batch modify attribute table

LLVM之父Chris Lattner:为什么我们要重建AI基础设施软件

AHB bus in stm32_ Apb2 bus_ Apb1 bus what are these
随机推荐
【HigherHRNet】 HigherHRNet 详解之 HigherHRNet的热图回归代码
Using keras in tensorflow to build convolutional neural network
Deconvolution popular detailed analysis and nn Convtranspose2d important parameter interpretation
Or in SQL, what scenarios will lead to full table scanning
ORM--数据库增删改查操作逻辑
反卷积通俗详细解析与nn.ConvTranspose2d重要参数解释
单片机(MCU)最强科普(万字总结,值得收藏)
学习记录——高精度加法和乘法
This article explains the complex relationship between MCU, arm, muc, DSP, FPGA and embedded system
C logging method
High number_ Chapter 1 space analytic geometry and vector algebra_ Quantity product of vectors
@Transcation的配置,使用,原理注意事项:
Some test points about coupon test
【acwing】789. 数的范围(二分基础)
浅谈日志中的返回格式封装格式处理,异常处理
EasyExcel读取写入简单使用
Guid primary key
Deadlock caused by non clustered index in SQL Server
【ORM框架】
How to cancel automatic saving of changes in sqlyog database