当前位置:网站首页>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]);
}
}
};
边栏推荐
- Wallys/IPQ6010 (IPQ6018 FAMILY) EMBEDDED BOARD WITH ON-BOARD WIFI DUAL BAND DUAL CONCURRENT
- Guid主键
- Appx代碼簽名指南
- ORM--数据库增删改查操作逻辑
- Programming features of ISP, IAP, ICP, JTAG and SWD
- Using keras in tensorflow to build convolutional neural network
- STM32 ADC and DMA
- Bean operation domain and life cycle
- 【二开】【JeecgBoot】修改分页参数
- STM32 product introduction
猜你喜欢
ORM model -- creation and query of data records
每周推荐短视频:L2级有哪些我们日常中经常会用到的功能?
电表远程抄表拉合闸操作命令指令
Word自动生成目录的方法
Embedded background - chip
ES6中的原型对象
【acwing】786. Number k
反卷积通俗详细解析与nn.ConvTranspose2d重要参数解释
The physical meaning of imaginary number J
Several schemes of building hardware communication technology of Internet of things
随机推荐
[learning notes - Li Hongyi] Gan (generation of confrontation network) full series (I)
China's first electronic audio category "Yamano electronic audio" digital collection is on sale!
Remote meter reading, switching on and off operation command
嵌入式背景知识-芯片
The Hal library is configured with a general timer Tim to trigger ADC sampling, and then DMA is moved to the memory space.
关于hzero-resource报错(groovy.lang.MissingPropertyException: No such property: weight for class)
Programming features of ISP, IAP, ICP, JTAG and SWD
Embedded background - chip
VS Code指定扩展安装位置
【ORM框架】
[second on] [jeecgboot] modify paging parameters
Deconvolution popular detailed analysis and nn Convtranspose2d important parameter interpretation
Postman interface test VI
串口通讯继电器-modbus通信上位机调试软件工具项目开发案例
Why is the reflection efficiency low?
Introduction to energy Router: Architecture and functions for energy Internet
Several schemes of building hardware communication technology of Internet of things
Vs code specifies the extension installation location
HAL库配置通用定时器TIM触发ADC采样,然后DMA搬运到内存空间。
2022.7.6DAY598