当前位置:网站首页>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;
}
边栏推荐
- L'enregistreur de disque dur NVR est connecté à easycvr par le Protocole GB 28181. Quelle est la raison pour laquelle l'information sur le canal de l'appareil n'est pas affichée?
- The cyberspace office announced the measures for data exit security assessment, which will come into force on September 1
- Jerry's test box configuration channel [chapter]
- Code of "digital image processing principle and Practice (matlab version)" part2[easy to understand]
- SAR影像质量评估
- 648. Word replacement
- 2022 how to evaluate and select low code development platforms?
- [200 opencv routines] 223 Polygon fitting for feature extraction (cv.approxpolydp)
- Build your own website (18)
- Validutil, "Rethinking the setting of semi supervised learning on graphs"
猜你喜欢
The maximum number of meetings you can attend [greedy + priority queue]
【JDBC Part 1】概述、获取连接、CRUD
[开源] .Net ORM 访问 Firebird 数据库
Crawler (17) - Interview (2) | crawler interview question bank
Jerry's about TWS pairing mode configuration [chapter]
TCP/IP 协议栈
cv2.resize函数报错:error: (-215:Assertion failed) func != 0 in function ‘cv::hal::resize‘
建立自己的网站(18)
Redis - basic use (key, string, list, set, Zset, hash, geo, bitmap, hyperloglog, transaction)
嵌入式开发:如何为项目选择合适的RTOS?
随机推荐
建立自己的网站(18)
怎样写一个增广矩阵到txt文件中
Codemail auto collation code of visual studio plug-in
ISO 26262 - considerations other than requirements based testing
#DAYU200体验官#MPPT光伏发电项目 DAYU200、Hi3861、华为云IotDA
Build your own website (18)
Ant destination multiple selection
Reinforcement learning - learning notes 9 | multi step TD target
How polardb-x does distributed database hotspot analysis
【colmap】稀疏重建转为MVSNet格式输入
你可曾迷茫?曾经的测试/开发程序员,懵懂的小菜C鸟升级......
Lingyun going to sea | saihe & Huawei cloud: jointly help the sustainable development of cross-border e-commerce industry
Demon daddy B3 read extensively in a small amount, and completed 20000 vocabulary+
海外代理推荐
使用 BlocConsumer 同时构建响应式组件和监听状态
Leetcode SQL first day
Validutil, "Rethinking the setting of semi supervised learning on graphs"
反爬通杀神器
SAR影像质量评估
PDF文档签名指南