?LeetCode刷題實(shí)戰(zhàn)205:同構(gòu)字符串
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.
題意
示例
示例 1:
輸入:s = "egg", t = "add"
輸出:true
示例 2:
輸入:s = "foo", t = "bar"
輸出:false
示例 3:
輸入:s = "paper", t = "title"
輸出:true
解題
class Solution:
def isIsomorphic(self, s: str, t: str) -> bool:
for i in range(len(s)):
if s.index(s[i]) != t.index(t[i]):
return False
return True
LeetCode1-200題匯總,希望對你有點(diǎn)幫助!
LeetCode刷題實(shí)戰(zhàn)201:數(shù)字范圍按位與
LeetCode刷題實(shí)戰(zhàn)202:快樂數(shù)
LeetCode刷題實(shí)戰(zhàn)203:移除鏈表元素
LeetCode刷題實(shí)戰(zhàn)204:計(jì)數(shù)質(zhì)數(shù)
評論
圖片
表情
