제 3의 문자열로 표현하여 문제를 해결할 수 있습니다.
https://leetcode.com/problems/isomorphic-strings/
Isomorphic Strings - LeetCode
Isomorphic Strings - 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 th
leetcode.com
솔루션
class Solution:
def isIsomorphic(self, s: str, t: str) -> bool:
s_count, t_count = 0,0
s_list, t_list = [], []
for i in range(len(s)):
# search s
for s_i, s_v in enumerate(s[:i+1]):
if s_v == s[i]:
s_list.append(s_count)
break
s_count += 1
# search t
for t_i, t_v in enumerate(t[:i+1]):
if t_v == t[i]:
t_list.append(t_count)
break
t_count += 1
if s_list == t_list:
return True
else :
return False
'컴퓨터공학 & 정보통신 > 알고리즘 문제 풀이' 카테고리의 다른 글
[LeetCode] 989. Add to Array-Form of Integer (0) | 2023.02.15 |
---|---|
[LeetCode] 278. First Bad Version (0) | 2023.02.13 |
[LeetCode] 724. Find Pivot Index (0) | 2023.02.13 |
[LeetCode] 167. Two Sum II - Input Array Is Sorted (0) | 2023.02.12 |
[LeetCode] 438. Find All Anagrams in a String (0) | 2023.02.12 |