Notice
Recent Posts
Recent Comments
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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
- 데이콘
- SW Expert Academy
- 편스토랑
- 금융문자분석경진대회
- ubuntu
- 파이썬
- 코로나19
- 프로그래머스
- Real or Not? NLP with Disaster Tweets
- Docker
- 맥북
- 우분투
- Git
- Baekjoon
- hackerrank
- 캐치카페
- 백준
- programmers
- 자연어처리
- Kaggle
- github
- 편스토랑 우승상품
- gs25
- AI 경진대회
- PYTHON
- 프로그래머스 파이썬
- 더현대서울 맛집
- dacon
- leetcode
- ChatGPT
Archives
- Today
- Total
솜씨좋은장씨
[leetCode] 1154. Day of the Year (Python) 본문
728x90
반응형
Given a string date representing a Gregorian calendar date formatted as YYYY-MM-DD, return the day number of the year.
Example 1:
Input: date = "2019-01-09"
Output: 9
Explanation: Given date is the 9th day of the year in 2019.
Example 2:
Input: date = "2019-02-10"
Output: 41
Example 3:
Input: date = "2003-03-01"
Output: 60
Example 4:
Input: date = "2004-03-01"
Output: 61
Constraints:
- date.length == 10
- date[4] == date[7] == '-', and all other date[i]'s are digits
- date represents a calendar date between Jan 1st, 1900 and Dec 31, 2019.
Solution
class Solution:
def dayOfYear(self, date: str) -> int:
year, month, day = int(date.split('-')[0]), int(date.split('-')[1]), int(date.split('-')[2])
days = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
answer = sum(days[:month-1]) + day
if ((year % 4 == 0 and year % 100 != 0) or year % 400 == 0) and month > 2:
answer = answer + 1
return answer
'Programming > 코딩 1일 1문제' 카테고리의 다른 글
[leetCode] 445. Add Two Numbers II (Python) (0) | 2020.07.27 |
---|---|
[leetCode] 1360. Number of Days Between Two Dates (Python) (0) | 2020.07.26 |
[leetCode] 342. Power of Four (Python) (0) | 2020.07.24 |
[leetCode] 692. Top K Frequent Words (Python) (0) | 2020.07.23 |
[leetCode] 386. Lexicographical Numbers (Python) (0) | 2020.07.22 |
Comments