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

边栏推荐
- Mini Program Optimization Practice
- torch.view()函数用法
- C语言-分值和循环语句
- L3-005 垃圾箱分布
- 语音鉴定软件
- leetcode 112.路经总和 递归
- The fledgling Xiao Li's 115th blog project notes on the creation of the domestic GD32F103RCT6 basic project
- NorFlash的存储原理
- 2022-08-07 mysql/stonedb slow SQL-subquery-semi-join
- 失业在家的6个月,我通过外包全款买了房:你看不起的行业,往往很赚钱
猜你喜欢

The fledgling Xiao Li's 115th blog project notes on the creation of the domestic GD32F103RCT6 basic project

ToDesk企业版上新 | 十大新功能,让企业远控更安全、更便捷、更流畅

风控策略必学|这种用决策树来挖掘规则的方法

【冷启动】快手《POSO: Personalized Cold Start Modules for Large-scale Recommender Systems》

Basic introduction to NLP

【模板引擎】velocity

失业在家的6个月,我通过外包全款买了房:你看不起的行业,往往很赚钱

【opencv】opencv开发包简介

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

leetcode: 874. Simulate a walking robot
随机推荐
package package
2022/08/06 Study Notes (day24) Collection
After being unemployed for 6 months at home, I bought a house with full payment through outsourcing: the industries you look down on are often very profitable
牛客多校第6场赛后学习 B(两种做法)G(两种做法)M(两种写法)J
vulnhub-DC-5 target drone penetration record
07查询表达式 及 page分页、order 排序《ThinkPHP6 入门到电商实战》
Qt 日志模块的个性化使用
leetcode 70. Stair Climbing Dynamic Programming
强网杯 2019-随便注 (堆叠注入)
y90. Chapter 6 Microservices, Service Grids and Envoy Combat -- Service Grid Basics (1)
一小时掌握vim基础用法
MYSQL export data dictionary
单主机docker 搭建 redis-cluster
Machine Learning Notes: Learning Rate Warmup
BMS 产品功能和详细设计规格
[Code Analysis] Graph small sample anomaly detection method: GDN: Few-shot Network Anomaly Detection via Cross-network Meta-learning
MySQL from entry to entry [20W word collection]
New retail project and offline warehouse core interview,, 220807,,
失业在家的6个月,我通过外包全款买了房:你看不起的行业,往往很赚钱
报错:[Intervention] Unable to preventDefault inside passive event listener due to target ...