当前位置:网站首页>242.有效的字母异位词
242.有效的字母异位词
2022-07-26 10:42:00 【Forest_1010】
使用数组a为s中每个字母+1计数,再遍历t,将出现的字母都减1,最后再遍历数组a,如果有出现不等于0的情况,说明不是异位词。
class Solution {
public:
bool isAnagram(string s, string t) {
char a[26]={
0};
for(int i=0;i<s.size();++i)
{
a[s[i]-'a']++;
}
for(int i=0;i<t.size();++i)
{
a[t[i]-'a']--;
}
for(int i=0;i<26;++i)
{
if(a[i]!=0)
return false;
}
return true;
}
};
数组就像一个简单的哈希表。
边栏推荐
- Flutter TextField设置高度并且自动换行,圆角边框去除下划线
- RT-Thread 学习笔记(三)---用SCons 构建编译环境
- 构建ARM嵌入式开发环境
- Simple use of json-c Library -- converting JSON files to struct
- 回到顶部的几种方案(js)
- Redis docker instance and data structure
- 13 managing resources by objects
- 从蚂蚁的觅食过程看团队研发(转载)
- C language calculation date interval days
- Redis special data type usage scenarios
猜你喜欢
[machine learning notes] [style transfer] deeplearning ai course4 4th week programming(tensorflow2)
Add touch screen driver for stemwin 5.22 on Shenzhou IV development board
从蚂蚁的觅食过程看团队研发(转载)
控制随机抽中几率 [ C# | Random ]
SAP ABAP 守护进程的实现方式
RT thread learning notes (III) -- building a compilation environment with scons
在神州IV开发板上为STemWin 5.22加入触屏驱动
Successfully transplanted stemwin v5.22 on Shenzhou IV development board
mysql20210906
RT-Thread 学习笔记(三)---用SCons 构建编译环境
随机推荐
Oracle创建索引
解决:无法加载文件 C:\Users\user\AppData\Roaming\npm\npx.ps1,因为在此系统上禁止运行脚本 。
2021-08-14三子棋
第4期:大学生提前职业技能准备之一
反射机制简述
SQL Server 之Sql语句创建数据库
.net operation redis set unordered collection
Sql Server 之SQL语句对基本表及其中的数据的创建和修改
Redis docker instance and data structure
鹏哥C语言——扫雷2021-08-16
13 managing resources by objects
MySQL速学-2021-09-01
[paper after dinner] deep mining external perfect data for chestx ray disease screening
扫雷pro版2021-08-19
如何实现临时的图形要素现实
px2rem-loader将px转化为rem,适配移动端vant-UI等框架
Build ARM embedded development environment
router.push(),router.repalce(),router.go()使用
点击el-dropdown-item/@click.native
[notes on machine learning] [building a cyclic neural network and its application] deeplearning ai course5 1st week programming(keras)