|
1 | 1 | packagecom.fishercoder.solutions;
|
2 | 2 |
|
3 |
| -/** |
4 |
| - * 1185. Day of the Week |
5 |
| - * |
6 |
| - * Given a date, return the corresponding day of the week for that date. |
7 |
| - * The input is given as three integers representing the day, month and year respectively. |
8 |
| - * Return the answer as one of the following values {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"}. |
9 |
| - * |
10 |
| - * Example 1: |
11 |
| - * Input: day = 31, month = 8, year = 2019 |
12 |
| - * Output: "Saturday" |
13 |
| - * |
14 |
| - * Example 2: |
15 |
| - * Input: day = 18, month = 7, year = 1999 |
16 |
| - * Output: "Sunday" |
17 |
| - * |
18 |
| - * Example 3: |
19 |
| - * Input: day = 15, month = 8, year = 1993 |
20 |
| - * Output: "Sunday" |
21 |
| - * |
22 |
| - * Constraints: |
23 |
| - * The given dates are valid dates between the years 1971 and 2100. |
24 |
| - * */ |
25 | 3 | publicclass_1185 {
|
26 | 4 | publicstaticclassSolution1 {
|
27 | 5 | /**
|
28 | 6 | * Time: O(1)
|
29 | 7 | * Space: O(1)
|
30 |
| - * |
| 8 | + * <p> |
31 | 9 | * Plain and simple algorithm:
|
32 | 10 | * based on the fact that 1/1/1971 is a Friday and calculate the given day.
|
33 |
| - * */ |
| 11 | + */ |
34 | 12 | publicStringdayOfTheWeek(intday,intmonth,intyear) {
|
35 | 13 | String[]daysInTheWeek =newString[]{"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"};
|
36 | 14 | int[]daysInTheMonth =newint[]{31,28,31,30,31,30,31,31,30,31,30,31};
|
|