当前位置:网站首页>Leetcode 205. isomorphic string (2022.07.24)
Leetcode 205. isomorphic string (2022.07.24)
2022-07-25 13:54:00 【ChaoYue_ miku】
Given two strings s and t , Judge whether they are isomorphic .
If s The characters in can be replaced according to some mapping relationship t , So these two strings are isomorphic .
Every character that appears should be mapped to another character , Without changing the order of characters . Different characters cannot be mapped to the same character , The same character can only be mapped to the same character , Characters can be mapped to themselves .
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
Tips :
1 <= s.length <= 5 * 104
t.length == s.length
s and t By any valid ASCII Character composition
source : Power button (LeetCode)
link :https://leetcode.cn/problems/isomorphic-strings
Method 1 : Hashtable
C++ Submission :
class Solution {
public:
bool isIsomorphic(string s, string t) {
unordered_map<char, char> s2t;
unordered_map<char, char> t2s;
int len = s.length();
for (int i = 0; i < len; ++i) {
char x = s[i], y = t[i];
if ((s2t.count(x) && s2t[x] != y) || (t2s.count(y) && t2s[y] != x)) {
return false;
}
s2t[x] = y;
t2s[y] = x;
}
return true;
}
};
边栏推荐
- Brush questions - Luogu -p1047 trees outside the school gate
- Talk about your understanding of hashcode and equals methods?
- leetcode202---快乐数
- Business data analysis of CDA level1 knowledge point summary
- Common problems of wireless relay acquisition instrument
- Brush questions - Luogu -p1059 clear random number
- Tm1637 four digit LED display module Arduino driver with second dot
- Practice of online problem feedback module (13): realize multi parameter paging query list
- Brush questions - Luogu -p1035 series summation
- LabVIEW的内部错误
猜你喜欢

在线问题反馈模块实战(十三):实现多参数分页查询列表

Setting of parameter configuration tool for wireless vibrating wire collector

飞沃科技IPO过会:年营收11.3亿 湖南文旅与沅澧投资是股东

Brush questions - Luogu -p1047 trees outside the school gate

Arduino code of key state machine for realizing single, double click, long press and other functions with esp32 timed interrupt

刷题-洛谷-P1046 陶陶摘苹果

Brush questions - Luogu -p1035 series summation

leetcode1 --两数之和

职场「数字人」不吃不睡007工作制,你「卷」得过它们吗?

刷题-洛谷-P1075 质因数分解
随机推荐
Mutex lock, spin lock, read-write lock... Clarify their differences and applications
Brush questions - Luogu -p1059 clear random number
6.27 uniapp project history
How to refactor embedded code?
Turn off automatic update when brew executes commands
IM system - some common problems of message streaming
力扣(LeetCode)205. 同构字符串(2022.07.24)
Lesson of C function without brackets
MySQL and Navicat installation and stepping on pits
leetcode202---快乐数
刷题-洛谷-P1152 欢乐的跳
Brush questions - Luogu -p1150 Peter's smoke
Hcip day 10 notes
依迅总经理孙峰:公司已完成股改,准备IPO
Experiment the Arduino code of NTP network timing alarm clock with esp32+tm1638
Hcip seventh day notes
CSV文本文件导入excel的四种方法
【力扣】645.错误的集合
Workplace "digital people" don't eat or sleep 007 work system, can you "roll" them?
dp-851