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
- auto encoder
- Sequence data
- SQL 데이터 분석 첫걸음
- Petri net
- Data Imbalance
- 프로세스 마이닝
- PM4Py
- OCSVM
- Digital Pathology
- 병리 AI
- Gausian Density Estimation
- Process Mining
- Meta heuristic
- 딥러닝
- Condensed neares neighbor rule
- multi modal
- Tomek links
- 국비지원교육
- Text generation
- XAI
- Fixed Learning
- One-Sided Selection
- Grad-CAM
- Inatance segmentation
- Clustering 기반 이상탐지
- Random Undersampling
- 밀도 기반 이상탐지
- GAN
- Generative modeling
- 거리 기반 이상탐지
Archives
- Today
- Total
Create Opportunities
[알고리즘] 숫자 변환 본문
Lv. 2
간단해 보였지만, while x=y: 정도밖에 생각을 못했다
정답 풀이 구현을 보고 놀람.
정답 풀이
def solution(x, y, n):
answer = 0
s = set()
s.add(x)
while s:
if y in s:
return answer
nxt = set() # new set
for i in s:
if i+n <= y:
nxt.add(i+n)
if i*2 <= y:
nxt.add(i*2)
if i*3 <= y:
nxt.add(i*3)
s = nxt
answer+=1
return -1
1. target 값인 y가 s안에 있을 때까지 돈다.
2. nxt라는 새로운 set을 만들어주고, 이 안에는 세 종류의 연산으로 구해지는 값을 넣는다.
3. s는 nxt로 update된다.
nxt set에서는 가능한 모든 연산값이 중복되지 않게 저장된다. 이 안에 target과 일치하는 값이 있다면? 종료하면 됨. 그리고 그 때의 연산 횟수 return.
출처: 프로그래머스 코딩 테스트 연습, https://school.programmers.co.kr/learn/challenges
'알고리즘' 카테고리의 다른 글
[알고리즘] 뒤에 있는 큰 수 찾기 (0) | 2023.03.06 |
---|---|
[알고리즘] 둘만의 암호 (1) | 2023.03.06 |
[알고리즘] 덧칠하기 (0) | 2023.03.02 |
[알고리즘] 대충 만든 자판 (0) | 2023.03.02 |
[알고리즘] 카드 뭉치 (0) | 2023.03.02 |