当前位置:网站首页>38. arrangement of strings
38. arrangement of strings
2022-06-12 05:19:00 【Be your goat】
The finger of the sword Offer 38. Arrangement of strings
Ideas : to flash back
Definition
(i>0&&!isVisited[i-1]&&s[i]==s[i-1])
Ensure that repeated elimination , The prerequisite string needs to be sorted
technological process
- Sorting ensures that duplicates can be excluded
- Traversal string ,
- If the current character is not traversed or does not meet the repetition condition , Add characters
- Recursively call
- Pop up the added string
- Return results
class Solution {
public:
vector<string> permutation(string s) {
vector<string> ans;
string tmp;
vector<bool> isVisited(s.size());
sort(s.begin(),s.end());
permutation(ans,tmp,s,isVisited);
return ans;
}
void permutation(vector<string>& ans,string& tmp,string& s,vector<bool>& isVisited){
if(tmp.size()==s.size()){
ans.push_back(tmp);
return;
}
for(int i=0;i<s.size();++i){
if((i>0&&!isVisited[i-1]&&s[i]==s[i-1])||isVisited[i]) continue;
tmp.push_back(s[i]);
isVisited[i]=true;
permutation(ans,tmp,s,isVisited);
tmp.pop_back();
isVisited[i]=false;
}
}
};
Time complexity O(nxn!) String Full Permutation O(n!), Required per spread O(n) Time generation
Spatial complexity O(n) need O(n) Stack space
边栏推荐
- Day18 creation and restoration of sparse array
- Three. JS import model demo analysis (with notes)
- A complete set of installation procedures (for learning and communication only)
- The master programmer "plays" a C program that is not like C
- Spatial distribution data of national multi-year average precipitation 1951-2021, temperature distribution data, evapotranspiration data, evaporation data, solar radiation data, sunshine data and wind
- Transpiration and evapotranspiration (ET) data, potential evapotranspiration, actual evapotranspiration data, temperature data, rainfall data
- SQL transaction
- Reason: Canonical names should be kebab-case (‘-‘ separated), lowercase alpha-numeric characters and
- Sword finger offer30 days re brush
- Realease package appears – missing type parameter
猜你喜欢

National land use data of 30m precision secondary classification

Computer network connected but unable to access the Internet

Transpiration and evapotranspiration (ET) data, potential evapotranspiration, actual evapotranspiration data, temperature data, rainfall data

Enhanced vegetation index evi, NDVI data, NPP data, GPP data, land use data, vegetation type data, rainfall data

Save the object in redis, save the bean in redis hash, and attach the bean map interoperation tool class

Multi thread learning 4. Sleep, wait, yield, join (), ThreadGroup control the running of threads

File contains (regardless of suffix) Apache log remote file contains PHP encapsulated pseudo protocol:

Introduction to MMS memory optimization of Hisilicon MPP service

Normalized vegetation index (NDVI) data, NPP data, GPP data, evapotranspiration data, vegetation type data, ecosystem type distribution data

Servlet core technology
随机推荐
Shandong University network security range experimental platform -- team and project introduction
Field xxxxDAO in com. nero. hua. service. impl. LoginServiceImpl required a bean of type
[backtracking method] queen n problem
Nbiot module me3616 at command mqtt connecting thingsboard
Harris corner detection principle-
[backtracking based on bit operation] queen n problem 2
Qs100 at command mqtt access thingsboard
Deploying a single node kubernetes cluster using rancher-2.5.5
IC验证中的force/release 学习整理(6)研究对 wire 类型信号的影响
Pupanvr- establishment of development environment and diary, addition of some basic tool functions (3)
12.24 day exercise -- Programming summation, 99 multiplication table, while loop and for loop exercises
Alsa architecture application aplay and amixer call relationship (from application layer to kernel driver)
Understanding of day16 array create query static and dynamic array array array performance in memory
Main business objects of pupanvr record (5)
Asp. Net core EF value conversion
[backtracking] backtracking method to solve combinatorial problems
Enhanced vegetation index evi, NDVI data, NPP data, GPP data, land use data, vegetation type data, rainfall data
Stm32f4 ll library multi-channel ADC
加速訓練之並行化 tf.data.Dataset 生成器
Why is Julia so popular?