[Q] [Easy]
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.
- 길이 다르면 애초에 아니니까 따로 빼줬다.
- str.index() 함수 활용하여 index 들을 확인해줬다.
- str.index() 함수는 중복되어도 첫번째 인덱스를 추출해주기 때문에 이럴때 활용하기 좋다.
# Answer
class Solution:
def isIsomorphic(self, s: str, t: str) -> bool:
# 길이 다르면 False
if len(s) != len(t):
return False
else:
s_index = []
t_index = []
for i in s:
s_index.append(s.index(i))
for j in t:
t_index.append(t.index(j))
if s_index == t_index:
return True
'Algorithm > Leetcode' 카테고리의 다른 글
[Top Interview 150 - Hashmap] 242. Valid Anagram (0) | 2024.10.12 |
---|---|
[Top Interview 150 - Hashmap] 290. Word Pattern (0) | 2024.10.12 |
[Top Interview 150 - Hashmap] 383. Ransom Note (0) | 2024.10.12 |
[Top Interview 150 - Two Pointers] 167. Two Sum II - Input Array Is Sorted (0) | 2024.10.12 |
[Top Interview 150 - Two Pointers] 392. Is Subsequence (1) | 2024.10.12 |