Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- OCSVM
- 밀도 기반 이상탐지
- auto encoder
- Fixed Learning
- 거리 기반 이상탐지
- Condensed neares neighbor rule
- Process Mining
- Text generation
- One-Sided Selection
- multi modal
- 프로세스 마이닝
- Inatance segmentation
- Digital Pathology
- Grad-CAM
- Tomek links
- GAN
- Gausian Density Estimation
- XAI
- Data Imbalance
- Petri net
- SQL 데이터 분석 첫걸음
- 병리 AI
- Random Undersampling
- PM4Py
- Clustering 기반 이상탐지
- Meta heuristic
- Generative modeling
- 국비지원교육
- Sequence data
- 딥러닝
Archives
- Today
- Total
Create Opportunities
[알고리즘] 둘만의 암호 본문
Lv. 1


내 풀이
import string
def solution(s, skip, index):
answer = ''
for spell in s:
for i in range(index):
spell = string.ascii_lowercase[(string.ascii_lowercase.index(spell) + 1) %26]
if spell in skip:
spell = string.ascii_lowercase[(string.ascii_lowercase.index(spell) + 1) %26]
answer += spell
return answer
왜 안되는지 아직 이해 못함.
정답 풀이
from string import ascii_lowercase
def solution(s, skip, index):
result = ''
a_to_z = set(ascii_lowercase)
a_to_z -= set(skip)
a_to_z = sorted(a_to_z)
l = len(a_to_z)
dic_alpha = { alpha:idx for idx, alpha in enumerate(a_to_z) }
for i in s:
result += a_to_z[(dic_alpha[i] + index) % l]
return result
set 활용함.
dictionary 형태로 {알파벳:인덱스} 저장하여 접근.
출처: 프로그래머스 코딩 테스트 연습, https://school.programmers.co.kr/learn/challenges
'알고리즘' 카테고리의 다른 글
[알고리즘] 개인정보 수집 유효기간 (0) | 2023.03.07 |
---|---|
[알고리즘] 뒤에 있는 큰 수 찾기 (0) | 2023.03.06 |
[알고리즘] 숫자 변환 (0) | 2023.03.02 |
[알고리즘] 덧칠하기 (0) | 2023.03.02 |
[알고리즘] 대충 만든 자판 (0) | 2023.03.02 |