当前位置:网站首页>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;
}
边栏推荐
- Oracle advanced (VI) Oracle expdp/impdp details
- The difference between NPM uninstall and RM direct deletion
- South China x99 platform chicken blood tutorial
- 强化学习-学习笔记9 | Multi-Step-TD-Target
- Have you ever been confused? Once a test / development programmer, ignorant gadget C bird upgrade
- null == undefined
- Programming mode - table driven programming
- Kirin Xin'an operating system derivative solution | storage multipath management system, effectively improving the reliability of data transmission
- Restore backup data on persistent volumes
- PKPM 2020软件安装包下载及安装教程
猜你喜欢

The latest Android interview collection, Android video extraction audio

An in-depth understanding of fp/fn/precision/recall
![[JDBC Part 1] overview, get connection, CRUD](/img/53/d79f29f102c81c9b0b7b439c78603b.png)
[JDBC Part 1] overview, get connection, CRUD

建立自己的网站(18)

It's worth seeing. Interview sites and interview skills

The function is really powerful!

强化学习-学习笔记9 | Multi-Step-TD-Target

Qt编写物联网管理平台39-报警联动

ByteDance Android interview, summary of knowledge points + analysis of interview questions

Solve the problem of uni in uni app Request sent a post request without response.
随机推荐
operator
Problems encountered in installing mysql8 for Ubuntu and the detailed installation process
Virtual machine network configuration in VMWare
嵌入式开发:如何为项目选择合适的RTOS?
Jerry's configuration of TWS cross pairing [article]
Jerry's key to initiate pairing [chapter]
Jerry's manual matching method [chapter]
Cv2.resize function reports an error: error: (-215:assertion failed) func= 0 in function ‘cv::hal::resize‘
NVR硬盘录像机通过国标GB28181协议接入EasyCVR,设备通道信息不显示是什么原因?
Paint basic graphics with custompaint
Reptile combat (VII): pictures of the king of reptiles' heroes
What if the win11u disk does not display? Solution to failure of win11 plug-in USB flash disk
2022 how to evaluate and select low code development platforms?
Jerry's about TWS channel configuration [chapter]
MIT6.S081-Lab9 FS [2021Fall]
Use br to recover backup data on azure blob storage
强化学习-学习笔记9 | Multi-Step-TD-Target
Usage of MySQL subquery keywords (exists)
Win11游戏模式怎么开启?Win11开启游戏模式的方法
Leetcode SQL first day