当前位置:网站首页>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;
}
边栏推荐
- Navicat connect 2002 - can't connect to local MySQL server through socket '/var/lib/mysql/mysql Sock 'solve
- Virtual machine network configuration in VMWare
- L2:ZK-Rollup的现状,前景和痛点
- Main functions of OS, Sys and random Standard Libraries
- 你可曾迷茫?曾经的测试/开发程序员,懵懂的小菜C鸟升级......
- Use blocconsumer to build responsive components and monitor status at the same time
- 谈谈制造企业如何制定敏捷的数字化转型策略
- Wechat official account oauth2.0 authorizes login and displays user information
- Redis - basic use (key, string, list, set, Zset, hash, geo, bitmap, hyperloglog, transaction)
- 【JDBC Part 1】概述、获取连接、CRUD
猜你喜欢

The little money made by the program ape is a P!

#DAYU200体验官#MPPT光伏发电项目 DAYU200、Hi3861、华为云IotDA

Demon daddy B3 read extensively in a small amount, and completed 20000 vocabulary+

海外代理推荐

L2:ZK-Rollup的现状,前景和痛点

How to make agile digital transformation strategy for manufacturing enterprises

Ten thousand word summary data storage, three knowledge points

Build your own website (18)

大数据开源项目,一站式全自动化全生命周期运维管家ChengYing(承影)走向何方?

Reinforcement learning - learning notes 9 | multi step TD target
随机推荐
Solve the problem of uni in uni app Request sent a post request without response.
Tsconfig of typescript TS basics JSON configuration options
强化学习-学习笔记9 | Multi-Step-TD-Target
Kirin Xin'an operating system derivative solution | storage multipath management system, effectively improving the reliability of data transmission
Win11如何解禁键盘?Win11解禁键盘的方法
Ad domain group policy management
MIT6.S081-Lab9 FS [2021Fall]
Redis - basic use (key, string, list, set, Zset, hash, geo, bitmap, hyperloglog, transaction)
Arlo's troubles
Which financial products will yield high returns in 2022?
Jerry's manual matching method [chapter]
NVR硬盘录像机通过国标GB28181协议接入EasyCVR,设备通道信息不显示是什么原因?
Matplotlib drawing interface settings
NVR硬盤錄像機通過國標GB28181協議接入EasyCVR,設備通道信息不顯示是什麼原因?
[colmap] sparse reconstruction is converted to mvsnet format input
Solve the problem of using uni app mediaerror mediaerror errorcode -5
解决uni-app中uni.request发送POST请求没有反应。
Tupu digital twin coal mining system to create "hard power" of coal mining
Demon daddy A3 stage near normal speed speech flow initial contact
Prometheus remote_ write InfluxDB,unable to parse authentication credentials,authorization failed