| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 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
- 잡생각
- 매일
- 운동
- 영어원서읽기
- 사이드
- 미드시청
- English
- Problem Solving
- leetcode
- 괜찮음
- 3줄정리
- 월간
- FIT XR
- 뭐든
- 화상영어
- Daily Challenge
- 개발자
- 링피트
- 읽기
- 스탭퍼
- 파비최
- realclass
- Writing
- 만화도
- 프로젝트
- 10분
- 리얼 클래스
- 영어공부
- 쓰릴오브파이트
- 30분
Archives
- Today
- Total
파비의 매일매일 공부기록
2023.02.02 Today's Challenge 본문
https://leetcode.com/problems/verifying-an-alien-dictionary/
Verifying an Alien Dictionary - LeetCode
Verifying an Alien Dictionary - In an alien language, surprisingly, they also use English lowercase letters, but possibly in a different order. The order of the alphabet is some permutation of lowercase letters. Given a sequence of words written in the ali
leetcode.com
단순히 한글자 비교로는 이슈가 생김.
Map으로 구현하면 됨
class Solution:
def isAlienSorted(self, words: List[str], order: str) -> bool:
map = {}
for i in range(len(order)):
map[order[i]] = i
for i in range(1, len(words)):
first = words[i-1]
second = words[i]
n = min(len(first), len(second))
flag = False
for j in range(n):
if map[first[j]] < map[second[j]]:
flag = True
break
elif map[first[j]] > map[second[j]]:
return False
if not flag and len(first) > len(second):
return False
return True반응형
'Problem Solving > LeetCode' 카테고리의 다른 글
| 2023.02.04 Today's Challenge (0) | 2023.02.04 |
|---|---|
| 2023.02.03 Today's Challenge (0) | 2023.02.03 |
| 2023.02.01 Today's Challenge (0) | 2023.02.01 |
| 2023.01.31 Today's Challenge (0) | 2023.01.31 |
| 2023.01.30 Today's Challenge (1) | 2023.01.30 |
Comments