문제
https://school.programmers.co.kr/learn/courses/30/lessons/181934
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
풀이
def solution(ineq, eq, n, m):
answer = 0
compare = ''
if ineq == '>' and eq == '=':
compare = '>='
if n >= m:
return 1
else:
return 0
if ineq == '<' and eq == '=':
compare = '<='
if n <= m:
return 1
else:
return 0
if ineq == '>' and eq == '!':
compare = '>'
if n > m:
return 1
else:
return 0
if ineq == '<' and eq == '!':
compare = '<'
if n < m:
return 1
else:
return 0
<다른 사람 코드>
def solution(ineq, eq, n, m):
return int(eval(str(n)+ineq+eq.replace('!', '')+str(m)))
설명
근데 이상하..게..도..? eval 함수 사용했을때가 시간이 더 많이 걸렸다...
** eval 함수
- 문자열로 표현되는 표현식을 실행해서 결과값을 받아오는 함수
'Coding Test > Python' 카테고리의 다른 글
| [Python] 회의실 배정(그리디) (0) | 2023.06.28 |
|---|---|
| [프로그래머스] 바탕화면 정리 (0) | 2023.06.18 |
| [프로그래머스] 더 크게 합치기 (0) | 2023.06.13 |
| [프로그래머스] 문자열 섞기 (0) | 2023.06.12 |
| [프로그래머스] 귤 고르기 (2) | 2023.06.09 |