当前位置:网站首页>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]);
}
}
};
边栏推荐
- Win10 installation vs2015
- Fiddler break point
- UnityWebRequest基础使用之下载文本、图片、AB包
- AHB bus in stm32_ Apb2 bus_ Apb1 bus what are these
- The new activity of "the arrival of twelve constellations and goddesses" was launched
- 根据设备信息进行页面跳转至移动端页面或者PC端页面
- [second on] [jeecgboot] modify paging parameters
- Prototype object in ES6
- Postman interface test II
- Memory ==c language 1
猜你喜欢

Win10 installation vs2015

ORM--查询类型,关联查询

Vs code specifies the extension installation location

ORM model -- associated fields, abstract model classes

How to cancel automatic saving of changes in sqlyog database

高数_第1章空间解析几何与向量代数_向量的数量积

VS Code指定扩展安装位置

Inno setup packaging and signing Guide

ORM -- query type, association query

Postman interface test II
随机推荐
Chris Lattner, père de llvm: Pourquoi reconstruire le logiciel d'infrastructure ai
Methods of adding centerlines and centerlines in SolidWorks drawings
STM32 ADC和DMA
Win10 installation vs2015
The Hal library is configured with a general timer Tim to trigger ADC sampling, and then DMA is moved to the memory space.
@Transcation的配置,使用,原理注意事项:
The new activity of "the arrival of twelve constellations and goddesses" was launched
STM32 Basics - memory mapping
HAL库配置通用定时器TIM触发ADC采样,然后DMA搬运到内存空间。
STM32中AHB总线_APB2总线_APB1总线这些是什么
Vs code specifies the extension installation location
学习记录——高精度加法和乘法
SQLyog数据库怎么取消自动保存更改
Deconvolution popular detailed analysis and nn Convtranspose2d important parameter interpretation
IO模型复习
[higherhrnet] higherhrnet detailed heat map regression code of higherhrnet
IPv4套接字地址结构
浅谈日志中的返回格式封装格式处理,异常处理
Memory ==c language 1
ES6中的函数进阶学习