当前位置:网站首页>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]);
}
}
};
边栏推荐
- 2022.7.6DAY598
- Use of JSON extractor originals in JMeter
- Several schemes of building hardware communication technology of Internet of things
- Bit operation ==c language 2
- . Net configuration system
- mysql插入数据创建触发器填充uuid字段值
- Postman tutorial - scripting
- Vs code specifies the extension installation location
- Phpcms realizes PC website access to wechat native payment
- The request object parses the request body and request header parameters
猜你喜欢
Remote meter reading, switching on and off operation command
[ORM framework]
【acwing】786. 第k个数
ArcGIS operation: converting DWG data to SHP data
高数_第1章空间解析几何与向量代数_向量的数量积
STM32 Basics - memory mapping
[second on] [jeecgboot] modify paging parameters
ISP、IAP、ICP、JTAG、SWD的编程特点
搭建物联网硬件通信技术几种方案
一文讲解单片机、ARM、MUC、DSP、FPGA、嵌入式错综复杂的关系
随机推荐
ORM模型--关联字段,抽象模型类
2022.7.3DAY595
Fiddler break point
JMeter loop controller and CSV data file settings are used together
Remote meter reading, switching on and off operation command
【华为机试真题详解】高矮个子排队
Parameter sniffing (2/2)
[second on] [jeecgboot] modify paging parameters
Inno setup packaging and signing Guide
Differences between MCU and MPU
Serial communication relay Modbus communication host computer debugging software tool project development case
Win10 installation vs2015
Several schemes of building hardware communication technology of Internet of things
Study summary of postgraduate entrance examination in July
Wallys/IPQ6010 (IPQ6018 FAMILY) EMBEDDED BOARD WITH ON-BOARD WIFI DUAL BAND DUAL CONCURRENT
ORM--查询类型,关联查询
大整数类实现阶乘
Appx code signing Guide
Introduction to uboot
Programming features of ISP, IAP, ICP, JTAG and SWD