当前位置:网站首页>Leetcode relaxation question - day of the week
Leetcode relaxation question - day of the week
2022-07-02 23:33:00 【qq5924db5b70f63】
package algorithm.dayOfTheWeek;
/**
* 1185. The day of the week
* Give you a date , Please design an algorithm to determine which day of the week it corresponds to .
*
* Enter three integers :day、month and year, Each represents a day 、 month 、 year .
*
* The result you return must be one of these values {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"}.
*
*
*
* Example 1:
*
* Input :day = 31, month = 8, year = 2019
* Output :"Saturday"
* Example 2:
*
* Input :day = 18, month = 7, year = 1999
* Output :"Sunday"
* Example 3:
*
* Input :day = 15, month = 8, year = 1993
* Output :"Sunday"
*
*
* Tips :
*
* The date given must be 1971 To 2100 Effective date between years .
*/
public class dayOfTheWeek {
public static String dayOfTheWeek(int day, int month, int year) {
String[] week = {"Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"};
int[] monthDays = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30};
// Calculate the number of days this year , Plus leap year
int days = 365 * (year-1971)+(year-1969)/4;
// Calculate this month's
for (int i = 0; i < month-1; i++) {
days+=monthDays[i];
}
if(year%400==0 ||(year %4==0 &&year%100!=0)){
days+=1;
}
// Calculate how many days have passed this month
days+=day;
//1971.1.1 It's Friday ,+3 Convert to Monday
return week[(days+3)%7];
}
public static void main(String[] args) {
int day = 17, month = 1, year = 2022;
System.out.println(dayOfTheWeek(day,month,year));
}
}
- 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.
- 39.
- 40.
- 41.
- 42.
- 43.
- 44.
- 45.
- 46.
- 47.
- 48.
- 49.
- 50.
- 51.
- 52.
- 53.
- 54.
- 55.
Can't , I can learn ; backward , I can catch up ; Fall down , I can stand up !
边栏推荐
- Numerical solution of partial differential equations with MATLAB
- 抖音实战~点赞数量弹框
- Implementation of VGA protocol based on FPGA
- [array] binary search
- Warning: implicitly declaring library function 'printf' with type 'int (const char *,...)‘
- 可知论与熟能生巧
- 【Proteus仿真】51单片机+LCD12864推箱子游戏
- Integration of revolution and batch normalization
- C MVC creates a view to get rid of the influence of layout
- JDBC練習案例
猜你喜欢

How difficult is it to be high? AI rolls into the mathematics circle, and the accuracy rate of advanced mathematics examination is 81%!

Connexion à distance de la tarte aux framboises en mode visionneur VNC

Intranet penetration | teach you how to conduct intranet penetration hand in hand

(stinger) use pystinger Socks4 to go online and not go out of the network host

golang入门:for...range修改切片中元素的值的另类方法

第三方支付功能测试点【杭州多测师_王sir】【杭州多测师】

MarkDown基本语法

数据集-故障诊断:西储大学轴承的各项数据以及数据说明

Ideal car × Oceanbase: when the new forces of car building meet the new forces of database

请求与响应
随机推荐
【ML】李宏毅三:梯度下降&分类(高斯分布)
[array] binary search
Go basic anonymous variable
Use redis to realize self increment serial number
[Verilog tutorial]
Convolution和Batch normalization的融合
Three solutions to frequent sticking and no response of explorer in win11 system
Arduino - character judgment function
RuntimeError: no valid convolution algorithms available in CuDNN
Cryptography -- the mode of block cipher
聊聊内存模型与内存序
抖音实战~点赞数量弹框
Use of recyclerview with viewbinding
基于FPGA的VGA协议实现
Fusion de la conversion et de la normalisation des lots
采用VNC Viewer方式远程连接树莓派
[adjustment] postgraduate enrollment of Northeast Petroleum University in 2022 (including adjustment)
Li Kou brush questions (2022-6-28)
Third party payment function test point [Hangzhou multi tester _ Wang Sir] [Hangzhou multi tester]
4 special cases! Schools in area a adopt the re examination score line in area B!