当前位置:网站首页>Minimum steps of manufacturing letter ectopic words - C language solution
Minimum steps of manufacturing letter ectopic words - C language solution
2022-04-21 14:45:00 【Mr Gao】
The minimum number of steps to make heterotopic words -c Language solution
Give you two strings of equal length s and t. In each step , You can choose to t Medium Any character Replace with Another character .
Return to make t Become s The minimum number of steps for an alphabetic ectopic word .
Letter heterotopic word Means the same letters , But the arrangement is different ( It could be the same ) String .
Example 1:
Output :s = “bab”, t = “aba”
Output :1
Tips : use ‘b’ Replace t The first of ‘a’,t = “bba” yes s A letter heterotopic word of .
Example 2:
Output :s = “leetcode”, t = “practice”
Output :5
Tips : Replace... With appropriate characters t Medium ‘p’, ‘r’, ‘a’, ‘i’ and ‘c’, send t become s Letter heteronym of .
Example 3:
Output :s = “anagram”, t = “mangaar”
Output :0
Tips :“anagram” and “mangaar” Itself is a group of letter ectopic words .
Example 4:
Output :s = “xxyyzz”, t = “xxyyzz”
Output :0
Example 5:
Output :s = “friend”, t = “family”
Output :4
This problem is not difficult , We count the number of different letters of two words , Then we can get the result according to the difference .
int minSteps(char * s, char * t){
int s_t[26];
int s_t2[26];
int i,j;
int n=0;
for(i=0;i<26;i++){
s_t[i]=0;
s_t2[i]=0;
}
i=0;
while(s[i]!='\0'){
s_t[s[i]-97]++;
s_t2[t[i]-97]++;
i++;
}
for(i=0;i<26;i++){
if(s_t[i]!=0){
if(s_t[i]-s_t2[i]<0)
n=n+abs(s_t[i]-s_t2[i]);
}
if(s_t2[i]!=0&&s_t[i]==0){
n=n+abs(s_t[i]-s_t2[i]);
}
}
return n;
}
版权声明
本文为[Mr Gao]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204211441332070.html
边栏推荐
- 均是素数——天梯训练赛
- 我们还能依赖Play to Earn经济获利多久?
- Six best practices for overseas ECS backup and recovery
- Experience and guidance of seniors preparing for the postgraduate entrance examination of Applied Psychology in Northeast Normal University in 2023
- 虫子 偶像稚晖君,向神看齐
- Alibaba cloud R & D collaboration service related agreement terms | cloud efficiency
- Mysql 执行流程
- Network security: introduce five common encryption algorithms
- C语言预处理问题
- How to apply for a free SSL certificate? Pagoda panel SSL certificate installation and deployment complete tutorial
猜你喜欢
随机推荐
期货开户找哪家公司?哪家期货公司最安全?
C语言预处理问题
虫子 偶像稚晖君,向神看齐
Legendary server setup tutorial, legendary GM permission command setting tutorial
WTL self drawing control library (cqstabctrl)
May day financial products have no income?
Script operation es
海外云服务器备份和恢复的6种最佳做法
用数字“钥匙”打开发展新空间
Mysql database (3)
String类
How to call uniCloud cloud storage in Nodejs project to upload middle note files
toString的使用与包装类的使用
异步操作之后让await后续的代码能够继续执行
【云驻共创】华为云数据库-基础知识
How to apply for a free SSL certificate? Pagoda panel SSL certificate installation and deployment complete tutorial
为什么覆盖equals()方法的时候,必须要覆盖hashCode()方法
How to provide CPU branch prediction efficiency at the code level
C# 11 对 ref 和 struct 的改进
元宇宙发展现状分析









