当前位置:网站首页>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'));

边栏推荐
- How to play knowledge graph in recommender system
- ES6对象字面量的新功能
- 项目分析(嵌入式产品Web化)
- Error: [Intervention] Unable to preventDefault inside passive event listener due to target ...
- KD树应用汇总
- leetcode 70.爬楼梯 动态规划
- This article will give you a thorough understanding of synchronized and Lock
- The live broadcast of agricultural products continues to heat up, Economic Daily: Don’t forget quality when rushing
- 单主机docker 搭建 redis-cluster
- awk语法-03-awk表达式(if语句、while循环、for循环)、awk中执行shell命令
猜你喜欢

分类、目标检测、语义分割、实例分割的区别

由联合体union引出的大小端问题

Exercise equipment responsive pbootcms template class web site

Let your text be seen by more people: Come and contribute, the payment is reliable!

内修昇思MindSpore AI框架,外重行业汇聚,华为大模型的不平凡之路

【模板引擎】velocity
![Error: [Intervention] Unable to preventDefault inside passive event listener due to target ...](/img/57/44e6bc7a330f075f79eb428475d89c.png)
Error: [Intervention] Unable to preventDefault inside passive event listener due to target ...

XDR technology

Monitoring tool Prometheus and project summary, 220805,,

【Review of Live Streaming】Synthesis MindSpore Usability SIG2022 First Half Review Summary
随机推荐
Young freshmen who yearn for open source | The guide to avoiding pits from open source to employment is here!
NetCore使用Dapper查询数据
二维码生成工具
Machine Learning Notes: Learning Rate Warmup
KD树应用汇总
多维度数组拉平到一维
向往的开源之多YOUNG新生 | 从开源到就业的避坑指南来啦!
y90. Chapter 6 Microservices, Service Grids and Envoy Combat -- Service Grid Basics (1)
硬盘基础知识
06 tp6 的数据更新(改)及删除 《ThinkPHP6 入门到电商实战》
Strong Net Cup 2019 - Casual Bet (Stacked Injection)
Building a High-Performance Platform on AWS Using Presto and Alluxio to Support Real-Time Gaming Services
B. Reverse Binary Strings
VSCode opens some records of C (embedded) projects
【论文分享】异质图上的小样本学习:HG-Meta: Graph Meta-learning over Heterogeneous Graphs
A line of code counts the number of occurrences of the specified string in the text
一文带你彻底了解synchronized 和 Lock
高薪程序员&面试题精讲系列134之微服务网关有哪些限流算法?如何实现限流?
The effect of base 0 or base 1 on the number of image iterations
机器学习笔记:学习率预热 warmup