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 | 31 |
Tags
- 재귀
- 구현
- level1
- level3
- N과M
- 브루트포스
- DP
- 가상메모리
- 가상메모리 관리
- BFS
- 스택
- level0
- programmers
- 수학
- 다이나믹 프로그래밍
- 운영체제
- dict
- 딕셔너리
- MYSQL
- level2
- 코딩테스트
- 파이썬
- 프로그래머스
- 힙
- 그리디
- python
- 백준
- dfs
- 다익스트라
- BOJ
Archives
- Today
- Total
동캄의 코딩도장
프로그래머스 level0 [분수의 덧셈] 파이썬 본문
https://school.programmers.co.kr/learn/courses/30/lessons/120808
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
#프로그래머스 분수의 덧셈
def solution(numer1, denom1, numer2, denom2):
lcm=LCM(denom1,denom2)
snum=numer1*(lcm//denom1)+numer2*(lcm//denom2)
gcd=GCD(snum,lcm)
answer = [snum//gcd,lcm//gcd]
return answer
def GCD(x,y):
while(y):
x,y=y,x%y
return x
def LCM(x,y):
result=(x*y)//GCD(x,y)
return result
최대 공약수와 최소 공배수를 이용하는 문제이다.
'코테 > 프로그래머스 level0' 카테고리의 다른 글
프로그래머스 level0 [최빈값 구하기] 파이썬 (0) | 2023.03.05 |
---|---|
프로그래머스 level0 [OX퀴즈] 파이썬 (0) | 2023.03.05 |
프로그래머스 level0 [연속된 수의 합] 파이썬 (0) | 2023.03.05 |
프로그래머스 level0 [안전지대] 파이썬 (0) | 2023.03.05 |
프로그래머스 level0 [겹치는 선분의 길이] 파이썬 (0) | 2023.03.05 |