当前位置:网站首页>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 !
边栏推荐
- What can I do after buying a domain name?
- 一文掌握基于深度学习的人脸表情识别开发(基于PaddlePaddle)
- Request and response
- Brief introduction to common sense of Zhongtai
- Quantitative analysis of PSNR, SSIM and RMSE
- YOLOX加强特征提取网络Panet分析
- JDBC practice cases
- What experience is there only one test in the company? Listen to what they say
- Golang common settings - modify background
- Convolution和Batch normalization的融合
猜你喜欢

Where is the win11 microphone test? Win11 method of testing microphone

4 special cases! Schools in area a adopt the re examination score line in area B!

Tiktok actual combat ~ number of likes pop-up box

RuntimeError: no valid convolution algorithms available in CuDNN
![Temperature measurement and display of 51 single chip microcomputer [simulation]](/img/83/73ee7f87787690aef7f0a9dab2c192.jpg)
Temperature measurement and display of 51 single chip microcomputer [simulation]

Fusion de la conversion et de la normalisation des lots
![Third party payment function test point [Hangzhou multi tester _ Wang Sir] [Hangzhou multi tester]](/img/d8/d22cbbaccb1594ee46aca098c41002.png)
Third party payment function test point [Hangzhou multi tester _ Wang Sir] [Hangzhou multi tester]

Is 408 not fragrant? The number of universities taking the 408 examination this year has basically not increased!

Solution: exceptiole 'xxxxx QRTZ_ Locks' doesn't exist and MySQL's my CNF file append lower_ case_ table_ Error message after names startup

YOLOX加强特征提取网络Panet分析
随机推荐
Writing of head and bottom components of non routing components
Speech recognition Series 1: speech recognition overview
JDBC教程
FOC矢量控制及BLDC控制中的端电压、相电压、线电压等概念别还傻傻分不清楚
Solution to boost library link error
MySQL Foundation
Go basic constant definition and use
(毒刺)利用Pystinger Socks4上线不出网主机
Agnosticism and practice makes perfect
提交代码流程
【Redis笔记】压缩列表(ziplist)
How difficult is it to be high? AI rolls into the mathematics circle, and the accuracy rate of advanced mathematics examination is 81%!
Yolox enhanced feature extraction network panet analysis
Explain promise usage in detail
YOLOX加强特征提取网络Panet分析
潘多拉 IOT 开发板学习(HAL 库)—— 实验4 串口通讯实验(学习笔记)
【ML】李宏毅三:梯度下降&分类(高斯分布)
A single element in an ordered array -- Valentine's Day mental problems
Quantitative analysis of PSNR, SSIM and RMSE
Talk about memory model and memory order