当前位置:网站首页>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;
}
};
边栏推荐
- How can information security engineers prepare for the soft exam in the second half of 2022?
- Vscode plug-in development
- 手里有点钱可以投资哪些理财产品?
- Congestion control of TCP
- Alibaba mqtt IOT platform "cloud product circulation" practice - the two esp32 achieve remote interoperability through the IOT platform
- Lesson of C function without brackets
- 【Platform IO编译Hifive1-revB】*** [.pio\build\hifive1-revb\src\setupGPIO.o] Error 1的解决办法
- [platform IO compile hifive1 revb] * * * [.pio\build\hifive1 revb\src\setupgpio.o] solution to error 1
- Data analysis business core
- @wrap 装饰器
猜你喜欢

Mxnet implementation of densenet (dense connection network)

How happy is the frisbee bureau? 2022 youth trendy Sports Report

运动豪华还是安全豪华?亚洲龙与沃尔沃S60该入手哪款?

Brush questions - Luogu -p1035 series summation

Brush questions - Luogu -p1150 Peter's smoke

Common problems in the use of wireless vibrating wire acquisition instrument

2022年下半年软考信息安全工程师如何备考?

Day1:三种语言暴刷牛客130题
![[platform IO compile hifive1 revb] * * * [.pio\build\hifive1 revb\src\setupgpio.o] solution to error 1](/img/a1/de197464e2a735d7ef012cea780da5.png)
[platform IO compile hifive1 revb] * * * [.pio\build\hifive1 revb\src\setupgpio.o] solution to error 1

Uniapp handles background transfer pictures
随机推荐
@classmethod 装饰器
Alibaba mqtt IOT platform "cloud product circulation" practice - the two esp32 achieve remote interoperability through the IOT platform
einsum(): operands do not broadcast with remapped shapes [original->remapped]: [1, 144, 20, 17]->[1,
pytest.mark.parametrize及mock使用
刷题-洛谷-P1152 欢乐的跳
Concurrent tool set for concurrent programming
Acquisition data transmission mode and online monitoring system of wireless acquisition instrument for vibrating wire sensor of engineering instrument
科隆新能源IPO被终止:拟募资6亿 先进制造与战新基金是股东
@wrap 装饰器
Leetcode 113. path sum II
命名空间与库
Common problems of wireless relay acquisition instrument
音视频技术开发周刊 | 255
Dr. Berkeley's "machine learning engineering" big truth; AI vice president '2022 ml job market' analysis; Large list of semiconductor start-ups; Large scale video face attribute data set; Cutting edge
Practice of online problem feedback module (13): realize multi parameter paging query list
Gym installation, invocation and registration
Advantages of wireless relay acquisition instrument and wireless network for engineering monitoring
word设置粘贴仅保留文本
Brush questions - Luogu -p1046 Tao Tao picking apples
Esp32 connects to Alibaba cloud mqtt IOT platform