当前位置:网站首页>LeetCode 205. Isomorphic Strings
LeetCode 205. Isomorphic Strings
2022-06-24 02:41:00 【freesan44】
Title address (205. Isomorphic Strings )
https://leetcode-cn.com/problems/isomorphic-strings/
Title Description
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 : It can be assumed s and t Same length .
Ideas
Use the dictionary to traverse whether it corresponds
Code
- Language support :Python3
Python3 Code:
class Solution:
def isIsomorphic(self, s: str, t: str) -> bool:
resDict = dict()
for index,val in enumerate(s):
if val in resDict:
if resDict[val] != t[index]:
return False
else:
resDict[val] = t[index]
resDict = dict()
for index,val in enumerate(t):
if val in resDict:
if resDict[val] != s[index]:
return False
else:
resDict[val] = s[index]
return TrueComplexity analysis
Make n Is array length .
- Time complexity :$O(n)$
- Spatial complexity :$O(n)$
边栏推荐
- Contour-v1.19.1 release
- How long can the trademark registration be completed? How to improve the speed of trademark registration?
- How to view the speech synthesis platform how to use the speech synthesis platform
- How to understand EDI requirements of trading partners
- The dealer management and control platform in the leather industry simplifies the purchase approval process and easily controls agents
- NFT metauniverse and the relationship between Games Golden Finance
- What are the performance characteristics of cloud desktop? How to choose the most cost-effective cloud desktop server?
- Start tcapulusdb process
- How about Shenzhen website construction? Is it expensive?
- MySQL Cases-MySQL 8.0.26 bug ERROR 1064 (42000) at line1: You have an error
猜你喜欢
随机推荐
Contour-v1.19.1 release
Official spoilers! Figure 1 understand Tencent security @2021 Tencent digital ecology Conference
[Tencent cloud load balancing CLB] cross region binding 2.0 (new version) idc-ip best practices!
What is the domain name trademark? What are the registration conditions for domain names and trademarks?
How to calculate the trademark registration fee? How much does it cost to register a trademark?
How to handle the abnormal state of easycvr national standard cascading superior display?
What are the general contents of the enterprise website construction scheme
Vscode common shortcut keys, updating
2021 game security industry summit: Security Co Construction and healthy development of escort industry
Uipickerview show and hide animation
How does Tencent cloud server build the official version of remote desktop computer to realize remote
Create and mount large files
How to access easynvr management platform through web pages without data?
Uiscrollview add gestures show and hide keyboard
Which cloud game service provider is more reliable when the cloud game server is open source
2020 language and intelligent technology competition was launched, and Baidu provided the largest Chinese data set
Why enterprises need fortress machines
What is a region name? Can a territory name be used for trademark registration?
Optimization of Clickhouse ConnectionPool link pool
What are the performance characteristics of cloud desktop? How to choose the most cost-effective cloud desktop server?


