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
- implement
- hash table
- Counting
- bit manipulation
- Data Structure
- Math
- string
- Class
- SQL
- geometry
- Number Theory
- 구현
- 자바
- database
- sorting
- Method
- 파이썬
- Stack
- Binary Search
- greedy
- 코테
- simulation
- dynamic programming
- two pointers
- array
- Matrix
- Tree
- java
- 코딩테스트
- Binary Tree
Archives
- Today
- Total
코린이의 소소한 공부노트
[LeetCode/Easy] 1154. Day of the Year 본문
1. Input
1) 날짜를 담은 문자열 변수 date
2) 날짜 형태는 yyyy-mm-dd
2. Output
1) 해당 날짜가 그 해의 몇번째 일인지 구해서 반환
3. Constraint
1) date.length == 10
2) date[4] == date[7] == '-'이고, 나머지는 전부 다 숫자이다.
3) 날짜는 1900년 1월 1일부터 2019년 12월 31일까지 중 1개이다,
4. Example
Input: date = "2019-02-10" -> Output: 41
설명:
- 1월은 31일
- 2월은 10일
- 총 합이 41일이므로, 41을 반환한다.
5. Code
1) 첫 코드(2022/07/14)
int m = Integer.parseInt(date.substring(5,7));
int d = Integer.parseInt(date.substring(8,10));
if(m==1)
return d;
boolean isLeapYear = false;
int y = Integer.parseInt(date.substring(0,4));
if(y%400==0 || (y%4==0 && y%100!=0))
isLeapYear = true;
List<Integer> day31 = new ArrayList(Arrays.asList(1,3,5,7,8,10,12));
List<Integer> day30 = new ArrayList(Arrays.asList(4,6,9,11));
for(int i=1 ; i<m ; i++){
if(day31.contains(i))
d += 31;
else if(day30.contains(i))
d += 30;
else
d += 28; // 윤년 고려X
}
if(isLeapYear && m>2)
return d+1;
else
return d;
'코딩테스트 풀이 > JAVA' 카테고리의 다른 글
[LeetCode/Easy] 1252. Cells with Odd Values in a Matrix (0) | 2022.12.24 |
---|---|
[LeetCode/Easy] 1221. Split a String in Balanced Strings (0) | 2022.12.23 |
[LeetCode/Easy] 1137. N-th Tribonacci Number (0) | 2022.12.20 |
[LeetCode/Easy] 1108. Defanging an IP Address (0) | 2022.12.20 |
[LeetCode/Easy] 1103. Distribute Candies to People (0) | 2022.12.20 |