当前位置:网站首页>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;
}
边栏推荐
- What stocks can a new account holder buy? Is the stock trading account safe
- Demon daddy guide post - simple version
- 强化学习-学习笔记9 | Multi-Step-TD-Target
- SAR image quality evaluation
- Demon daddy B3 read extensively in a small amount, and completed 20000 vocabulary+
- [open source] Net ORM accessing Firebird database
- DBSync新增对MongoDB、ES的支持
- Jenkins user rights management
- Reinforcement learning - learning notes 8 | Q-learning
- ByteDance Android interview, summary of knowledge points + analysis of interview questions
猜你喜欢
Reinforcement learning - learning notes 9 | multi step TD target
EasyCVR配置中心录像计划页面调整分辨率时的显示优化
解决uni-app中uni.request发送POST请求没有反应。
Use json Stringify() to realize deep copy, be careful, there may be a huge hole
Crawler (17) - Interview (2) | crawler interview question bank
Why can't win11 display seconds? How to solve the problem that win11 time does not display seconds?
Pre sale 179000, hengchi 5 can fire? Product power online depends on how it is sold
Solve the problem of uni in uni app Request sent a post request without response.
Focusing on safety in 1995, Volvo will focus on safety in the field of intelligent driving and electrification in the future
Matplotlib drawing interface settings
随机推荐
Time standard library
[JDBC Part 1] overview, get connection, CRUD
Matplotlib drawing interface settings
Display optimization when the resolution of easycvr configuration center video recording plan page is adjusted
Contour layout of margin
谈谈制造企业如何制定敏捷的数字化转型策略
Preparing for the interview and sharing experience
强化学习-学习笔记9 | Multi-Step-TD-Target
Take the intersection of two sets
如何实现横版游戏中角色的移动控制
【JDBC Part 1】概述、获取连接、CRUD
Leetcode SQL first day
Use camunda to do workflow design and reject operations
Codemail auto collation code of visual studio plug-in
Node:504 error reporting
[open source] Net ORM accessing Firebird database
双塔模型的最强出装,谷歌又开始玩起“老古董”了?
2022 how to evaluate and select low code development platforms?
[advanced MySQL] index details (I): index data page structure
Jenkins user rights management