当前位置:网站首页>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 !
边栏推荐
- 购买完域名之后能干什么事儿?
- Convolution和Batch normalization的融合
- Three solutions to frequent sticking and no response of explorer in win11 system
- 采用VNC Viewer方式远程连接树莓派
- Go basic anonymous variable
- Win11如何开启目视控制?Win11开启目视控制的方法
- Brief introduction to common sense of Zhongtai
- Use redis to realize self increment serial number
- How to maintain the brand influence of clothing enterprises
- PHP get real IP
猜你喜欢
What can I do after buying a domain name?
CDN 加速,需要域名先备案
I've been interviewed. The starting salary is 16K
Bean load control
Alibaba cloud award winning experience: how to use polardb-x
Detailed explanation of 'viewpager' in compose | developer said · dtalk
Integration of revolution and batch normalization
Implementation of VGA protocol based on FPGA
Eight honors and eight disgraces of the programmer version~
第三方支付功能测试点【杭州多测师_王sir】【杭州多测师】
随机推荐
The difference between new and make in golang
4 special cases! Schools in area a adopt the re examination score line in area B!
JSON data transfer parameters
数据集-故障诊断:西储大学轴承的各项数据以及数据说明
Quantitative analysis of PSNR, SSIM and RMSE
JDBC教程
VIM interval deletion note
一文掌握基于深度学习的人脸表情识别开发(基于PaddlePaddle)
高数有多难?AI 卷到数学圈,高数考试正确率 81%!
Eight bit responder [51 single chip microcomputer]
Solving ordinary differential equations with MATLAB
非路由组件之头部组件和底部组件书写
Go basic constant definition and use
Compose 中的 'ViewPager' 详解 | 开发者说·DTalk
20220527_ Database process_ Statement retention
聊聊内存模型与内存序
为什么RTOS系统要使用MPU?
What if win11 can't turn off the sticky key? The sticky key is cancelled but it doesn't work. How to solve it
php 获取真实ip
ADC of stm32