Notice
Recent Posts
Recent Comments
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 | 31 |
Tags
- 코로나19
- 캐치카페
- SW Expert Academy
- 프로그래머스
- ubuntu
- AI 경진대회
- Baekjoon
- hackerrank
- 파이썬
- 더현대서울 맛집
- Git
- 편스토랑
- PYTHON
- Kaggle
- Docker
- leetcode
- Real or Not? NLP with Disaster Tweets
- 우분투
- 데이콘
- programmers
- ChatGPT
- 편스토랑 우승상품
- gs25
- 백준
- 프로그래머스 파이썬
- github
- 맥북
- 자연어처리
- dacon
- 금융문자분석경진대회
Archives
- Today
- Total
솜씨좋은장씨
[leetCode] 205. Isomorphic Strings (Python) 본문
728x90
반응형
Given two strings s and t, determine if they are isomorphic.
Two strings 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.
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
Note:
You may assume both s and t have the same length.
Solution
class Solution:
def isIsomorphic(self, s: str, t: str) -> bool:
check_dict = {}
check_dict_2 = {}
answer = True
for s_c, t_c in zip(s, t):
if s_c not in check_dict.keys():
check_dict[s_c] = t_c
else:
if check_dict[s_c] != t_c:
answer = False
break
if answer == True:
for s_c, t_c in zip(s, t):
if t_c not in check_dict_2.keys():
check_dict_2[t_c] = s_c
else:
if check_dict_2[t_c] != s_c:
answer = False
break
return answer
'Programming > 코딩 1일 1문제' 카테고리의 다른 글
[leetCode] 35. Search Insert Position (Python) (0) | 2020.08.05 |
---|---|
[leetCode] 290. Word Pattern (Python) (0) | 2020.08.04 |
[leetCode] 434. Number of Segments in a String (Python) (0) | 2020.08.02 |
[leetCode] 1528. Shuffle String (Python) (0) | 2020.08.02 |
[leetCode] 884. Uncommon Words from Two Sentences (Python) (0) | 2020.07.31 |
Comments