当前位置:网站首页>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;
}
边栏推荐
- Demon daddy C
- Win11如何解禁键盘?Win11解禁键盘的方法
- Demon daddy guide post - simple version
- Awk processing JSON processing
- The strongest installation of the twin tower model, Google is playing "antique" again?
- Matplotlib drawing interface settings
- South China x99 platform chicken blood tutorial
- Backup tidb cluster to persistent volume
- 你可曾迷茫?曾经的测试/开发程序员,懵懂的小菜C鸟升级......
- Virtual machine network configuration in VMWare
猜你喜欢
Jenkins user rights management
【Azure微服务 Service Fabric 】因证书过期导致Service Fabric集群挂掉(升级无法完成,节点不可用)
Why can't win11 display seconds? How to solve the problem that win11 time does not display seconds?
Using enumeration to realize English to braille
你可曾迷茫?曾经的测试/开发程序员,懵懂的小菜C鸟升级......
ByteDance senior engineer interview, easy to get started, fluent
QT compile IOT management platform 39 alarm linkage
PDF文档签名指南
PKPM 2020软件安装包下载及安装教程
Paint basic graphics with custompaint
随机推荐
Win11U盘不显示怎么办?Win11插U盘没反应的解决方法
An in-depth understanding of fp/fn/precision/recall
DNS series (I): why does the updated DNS record not take effect?
Lingyun going to sea | saihe & Huawei cloud: jointly help the sustainable development of cross-border e-commerce industry
How to make agile digital transformation strategy for manufacturing enterprises
cv2.resize函数报错:error: (-215:Assertion failed) func != 0 in function ‘cv::hal::resize‘
Automatic classification of defective photovoltaic module cells in electronic images
Tcp/ip protocol stack
The strongest installation of the twin tower model, Google is playing "antique" again?
The function is really powerful!
Description of the difference between character varying and character in PostgreSQL database
谈谈制造企业如何制定敏捷的数字化转型策略
How much does it cost to develop a small program mall?
Qt编写物联网管理平台39-报警联动
Magic weapon - sensitive file discovery tool
Demon daddy C
Arlo's troubles
Redis - basic use (key, string, list, set, Zset, hash, geo, bitmap, hyperloglog, transaction)
An overview of the latest research progress of "efficient deep segmentation of labels" at Shanghai Jiaotong University, which comprehensively expounds the deep segmentation methods of unsupervised, ro
2022 how to evaluate and select low code development platforms?