当前位置:网站首页>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;
}
边栏推荐
- Tsconfig of typescript TS basics JSON configuration options
- Matplotlib drawing interface settings
- npm uninstall和rm直接删除的区别
- Ternary expressions, generative expressions, anonymous functions
- Jerry's about TWS channel configuration [chapter]
- Jerry's power on automatic pairing [chapter]
- Preparing for the interview and sharing experience
- Cv2.resize function reports an error: error: (-215:assertion failed) func= 0 in function ‘cv::hal::resize‘
- Lingyun going to sea | saihe & Huawei cloud: jointly help the sustainable development of cross-border e-commerce industry
- Static test tool
猜你喜欢

建立自己的网站(18)

【Azure微服务 Service Fabric 】因证书过期导致Service Fabric集群挂掉(升级无法完成,节点不可用)

Ten thousand word summary data storage, three knowledge points

The function is really powerful!

Win11如何解禁键盘?Win11解禁键盘的方法

Matplotlib drawing interface settings

Use camunda to do workflow design and reject operations
![[open source] Net ORM accessing Firebird database](/img/a2/4eff4f0af53bf3b9839a73019a212f.png)
[open source] Net ORM accessing Firebird database

How does win11 unblock the keyboard? Method of unlocking keyboard in win11

Display optimization when the resolution of easycvr configuration center video recording plan page is adjusted
随机推荐
Open source OA development platform: contract management user manual
Contour layout of margin
Time standard library
Which futures company is the safest to open a futures account?
[JDBC Part 1] overview, get connection, CRUD
Demon daddy guide post - simple version
null == undefined
648. Word replacement
Navicat connect 2002 - can't connect to local MySQL server through socket '/var/lib/mysql/mysql Sock 'solve
Jerry's manual matching method [chapter]
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?
Ad domain group policy management
ByteDance senior engineer interview, easy to get started, fluent
Use br to back up tidb cluster data to azure blob storage
Embedded development: how to choose the right RTOS for the project?
npm uninstall和rm直接删除的区别
嵌入式开发:如何为项目选择合适的RTOS?
The strongest installation of the twin tower model, Google is playing "antique" again?
Ant destination multiple selection
Win11时间怎么显示星期几?Win11怎么显示今天周几?