정수 배열 date1과 date2가 주어집니다. 두 배열은 각각 날짜를 나타내며 [year, month, day] 꼴로 주어집니다. 각 배열에서 year는 연도를, month는 월을, day는 날짜를 나타냅니다.
만약 date1이 date2보다 앞서는 날짜라면 1을, 아니면 0을 return 하는 solution 함수를 완성해 주세요.
code - 1차
def solution(date1, date2):
if date2[0] > date1[0]:
return 1
elif date2[0] >= date1[0] and date2[1] > date1[1]:
return 1
elif date2[0] >= date1[0] and date2[1] >= date1[1] and date2[2] > date1[2]:
return 1
else:
return 0
code - 2차
def solution(date1, date2):
return int(date1 < date2)
- date1 < date2
- 각 첫 번째 요소, 두 번째 요소, 세 번째 요소를 비교하여 True or False 값을 반환합니다.
- int(...)
- 그 반환한 값을 int로 감싸면 True일 땐 1, False일 땐 0이 결과로 출력됩니다.
https://github.com/seonmin5/codingtest_Python
GitHub - seonmin5/codingtest_Python
Contribute to seonmin5/codingtest_Python development by creating an account on GitHub.
github.com
반응형
'Python' 카테고리의 다른 글
| [Python/Bronze II] 알파벳 찾기 - 10809, find (0) | 2024.08.31 |
|---|---|
| [Python/level 0] 세로 읽기 - 181904, 리스트 슬라이싱 (0) | 2024.08.31 |
| [Python/level 0] 빈 배열에 추가, 삭제하기 - 181860, enumerate, extend, del (1) | 2024.08.31 |
| [Python/level 1] 두 정수 사이의 합 - 12912, sum + 리스트 컴프리헨션 vs. for 반복문 (0) | 2024.08.31 |
| [Python/level 0] 배열의 원소만큼 추가하기 - 181861 (1) | 2024.08.31 |