当前位置: 首页 > news >正文

LeetCode205. Isomorphic Strings

文章目录

    • 一、题目
    • 二、题解

一、题目

Given two strings s and t, determine if they are isomorphic.

Two strings s and t are isomorphic if the characters in s can be replaced to get t.

All occurrences of a character must be replaced with another character while preserving the order of characters. No two characters may map to the same character, but a character may map to itself.

Example 1:

Input: s = “egg”, t = “add”
Output: true
Example 2:

Input: s = “foo”, t = “bar”
Output: false
Example 3:

Input: s = “paper”, t = “title”
Output: true

Constraints:

1 <= s.length <= 5 * 104
t.length == s.length
s and t consist of any valid ascii character.

二、题解

class Solution {
public:bool isIsomorphic(string s, string t) {int n = s.size();unordered_map<char,char> map1;unordered_map<char,char> map2;for(int i = 0;i < n;i++){//如果在map1中不存在if(map1.find(s[i]) == map1.end()) map1[s[i]] = t[i];else{if(map1[s[i]] != t[i]) return false;}//如果映射在map2中不存在if(map2.find(t[i]) == map2.end()) map2[t[i]] = s[i];else{if(map2[t[i]] != s[i]) return false;}}return true;}
};
http://www.lryc.cn/news/258785.html

相关文章:

  • Event Driven设计模式
  • PostgreSql 设置自增字段
  • 什么是泊松图像混合
  • OpenAI 承认 ChatGPT 最近确实变懒,承诺修复问题
  • 创作活动(四十九)———低代码:美味膳食或垃圾食品?
  • 【DL-TensorFlow遇错】TensorFlow中遇错合集
  • pymysql代替mysqlclient,解决mysqlclient因版本不兼容无法安装成功而无法连接mysql的问题
  • uni-app 设置当前page界面进入直接变为横屏模式
  • Mysql的多表联合查询
  • Linux上使用Python的requests库进行HTTP请求
  • 图像处理领域的应用
  • MySQL笔记-第18章_MySQL8其它新特性
  • C语言—每日选择题—Day46
  • flex布局,换行的元素上下设置间距
  • 【智能家居】八、监控摄像采集、人脸识别比对进行开门功能点
  • golang的文件操作
  • 数据库版本管理框架-Flyway(从入门到精通)
  • 外网访问内网服务器使用教程
  • C# Dictionary 利用 ContainsValue 查询指定值是否已经存在
  • 招不到人?用C语言采集系统批量采集简历
  • HXDSP2441-Demo板
  • 静态路由的原理和配置
  • Ubuntu20.04降低linux版本到5.4.0-26-generic
  • C++ 类型萃取
  • 【JVM从入门到实战】(四)类的生命周期
  • 2023年度美食关键词-葱油花卷
  • 「Verilog学习笔记」简易秒表
  • 《每天一个Linux命令》 -- (12) file命令
  • 如何使用ArcGIS Pro制作类似CAD的尺寸注记
  • Go语言bufio包的使用