当前位置:网站首页>leetcode-isomorphic string judgment
leetcode-isomorphic string judgment
2022-08-08 04:30:00 【zjLOVEcyj】
- 同构字符串
给定两个字符串 s 和 t ,判断它们是否是同构的.
如果 s 中的字符可以按某种映射关系替换得到 t ,那么这两个字符串是同构的.
每个出现的字符都应当映射到另一个字符,同时不改变字符的顺序.不同字符不能映射到同一个字符上,相同字符只能映射到同一个字符上,字符可以映射到自己本身.
示例 1:
输入:s = “egg”, t = “add”
输出:true
示例 2:
输入:s = “foo”, t = “bar”
输出:false
示例 3:
输入:s = “paper”, t = “title”
输出:true
提示:
1 <= s.length <= 5 * 104
t.length == s.length
s 和 t 由任意有效的 ASCII 字符组成
let isIsomorphic = function(s, t) {
//return different lengthfalse
if (s.length !== t.length) return false
let map1 = {
}//建立映射表
for (let i = 0; i < s.length; i++) {
if (!map1[s[i]]) {
//If not in the mapping table, add it
map1[s[i]] = t[i]
} else {
//If there is existing in the mapping table, it is judged whether it conforms to the previous mapping 不符合直接返回false
if (t[i] !== map1[s[i]]) return false
}
}
//Finally, determine the mapping tablevalueAre all different characters,That is, it meets the requirement that different characters cannot be mapped to the same character Return if notfalse
if (Array.from(new Set(Object.values(map1))).length !== Object.values(map1).length) return false
return true
};
console.log(isIsomorphic('ab', 'cc'));

边栏推荐
- A line of code counts the number of occurrences of the specified string in the text
- How to play knowledge graph in recommender system
- ES6剩余参数的使用
- Exercise equipment responsive pbootcms template class web site
- Basic introduction to NLP
- 类似Bugfree的9大在线缺陷管理软件
- L3-005 垃圾箱分布
- MySQL from entry to entry [20W word collection]
- 由联合体union引出的大小端问题
- 一小时掌握vim基础用法
猜你喜欢

使用ffmpeg解码音频sdl(push)播放

package package

Mini Program Optimization Practice

10 must-have free tools for self-media people to operate quickly and efficiently

New retail project and offline warehouse core interview,, 220807,,

The storage principle of NorFlash

vulnhub-DC-5 target drone penetration record
![MySQL from entry to entry [20W word collection]](/img/da/1a40e831aa541001773bb76fd369f4.png)
MySQL from entry to entry [20W word collection]

走进音视频的世界——RGB与YUV格式

初出茅庐的小李第115篇博客项目笔记之国产GD32F103RCT6基础工程创建
随机推荐
使用ffmpeg解码音频sdl(push)播放
Monitoring tool Prometheus and project summary, 220805,,
MySql入门教程
MindFusion.WPF Pack 2022.R1
L3-007 ladder map (test point 2 is stuck, you can see it)
New ToDesk Enterprise Edition | Ten new features to make enterprise remote control safer, more convenient and smoother
Qt 日志模块的个性化使用
reduce具体使用以及使用reduce,toString,flat进行数组降维
Mini Program Optimization Practice
多维度数组拉平到一维
06 tp6 的数据更新(改)及删除 《ThinkPHP6 入门到电商实战》
leetcode: 874. Simulate a walking robot
BMS 产品功能和详细设计规格
How to play knowledge graph in recommender system
【代码分析】图小样本异常检测方法:GDN:Few-shot Network Anomaly Detection via Cross-network Meta-learning
The use of mmedicting get_flops. Py
ES6解构赋值的使用说明
32. Do you know how Redis strings are implemented?
拒绝“内卷”跃迁软件测试最大门槛,我是如何从月薪8K到15K的?
RecycleView配合Adapter调用notifyDataSetChanged闪屏?