当前位置:网站首页>Interview question 01.02 Determine whether it is character rearrangement - auxiliary array algorithm
Interview question 01.02 Determine whether it is character rearrangement - auxiliary array algorithm
2022-07-07 22:03:00 【Mr Gao】
Interview questions 01.02. Determine whether to rearrange characters for each other
Given two strings s1 and s2, Please write a program , After determining the character rearrangement of one of the strings , Can it be another string .
Example 1:
Input : s1 = “abc”, s2 = “bca”
Output : true
Example 2:
Input : s1 = “abc”, s2 = “bad”
Output : false
For this question , In fact, it's relatively simple , We can add an auxiliary array to judge the problem , Make an auxiliary array , Storage s1 The number of letters in the , then , Yes s2 Subtract the number of letters stored in , The number of each letter stored in the auxiliary array is 0, return true, Otherwise return to false
The solution code is as follows :
bool CheckPermutation(char* s1, char* s2){
int r[26];
int i=0;
for(i=0;i<26;i++){
r[i]=0;
}
i=0;
while(s1[i]!='\0'){
r[s1[i]-'a']++;
i++;
}
i=0;
while(s2[i]!='\0'){
r[s2[i]-'a']--;
i++;
}
for(i=0;i<26;i++){
if(r[i]!=0){
return false;
}
}
return true;
}
边栏推荐
- 谈谈制造企业如何制定敏捷的数字化转型策略
- [JDBC Part 1] overview, get connection, CRUD
- Kirin Xin'an operating system derivative solution | storage multipath management system, effectively improving the reliability of data transmission
- Main functions of OS, Sys and random Standard Libraries
- Jerry's about TWS pairing mode configuration [chapter]
- Solve the problem of uni in uni app Request sent a post request without response.
- Ternary expressions, generative expressions, anonymous functions
- 大数据开源项目,一站式全自动化全生命周期运维管家ChengYing(承影)走向何方?
- Demon daddy B3 read extensively in a small amount, and completed 20000 vocabulary+
- Validutil, "Rethinking the setting of semi supervised learning on graphs"
猜你喜欢

Automatic classification of defective photovoltaic module cells in electronic images

反爬通杀神器

你可曾迷茫?曾经的测试/开发程序员,懵懂的小菜C鸟升级......

Goal: do not exclude yaml syntax. Try to get started quickly

Reptile combat (VII): pictures of the king of reptiles' heroes
![[开源] .Net ORM 访问 Firebird 数据库](/img/a2/4eff4f0af53bf3b9839a73019a212f.png)
[开源] .Net ORM 访问 Firebird 数据库

648. Word replacement

海外代理推荐

Tcp/ip protocol stack

ISO 26262 - considerations other than requirements based testing
随机推荐
Demon daddy guide post - simple version
The function is really powerful!
Two kinds of updates lost and Solutions
Pre sale 179000, hengchi 5 can fire? Product power online depends on how it is sold
Talk about relational database and serverless
How polardb-x does distributed database hotspot analysis
Use blocconsumer to build responsive components and monitor status at the same time
Magic weapon - sensitive file discovery tool
Usage of MySQL subquery keywords (exists)
[开源] .Net ORM 访问 Firebird 数据库
Ad domain group policy management
Song list 11111
648. Word replacement
【colmap】稀疏重建转为MVSNet格式输入
Use br to recover backup data on azure blob storage
[advanced MySQL] index details (I): index data page structure
Default constraint and zero fill constraint of MySQL constraint
The difference between NPM uninstall and RM direct deletion
Tcp/ip protocol stack
双塔模型的最强出装,谷歌又开始玩起“老古董”了?