-
Notifications
You must be signed in to change notification settings - Fork 118
/
Copy pathDay of the Year..java
38 lines (37 loc) · 996 Bytes
/
Day of the Year..java
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
32
33
34
35
36
37
38
// Runtime: 14 ms (Top 18.15%) | Memory: 44.20 MB (Top 65.48%)
class Solution {
public int dayOfYear(String date) {
int days = 0;
int[] arr = {31,28,31,30,31,30,31,31,30,31,30,31};
String[] year = date.split("-");
int y = Integer.valueOf(year[0]);
int month = Integer.valueOf(year[1]);
int day = Integer.valueOf(year[2]);
boolean leap = false;
for(int i = 0; i < month-1; i++){
days = days+arr[i];
}
days = days+day;
if(y%4==0){
if(y%100==0){
if(y%400==0){
leap = true;
}
else{
leap = false;
}
}
else{
leap = true;
}
}
else{
leap = false;
}
if(leap==true && month>2){
System.out.println("Leap Year");
days = days+1;
}
return days;
}
}