当前位置:网站首页>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 !
边栏推荐
- 潘多拉 IOT 开发板学习(HAL 库)—— 实验3 按键输入实验(学习笔记)
- 【Proteus仿真】51单片机+LCD12864推箱子游戏
- Talk about memory model and memory order
- Simple square wave generating circuit [51 single chip microcomputer and 8253a]
- SharedPreferences 保存List<Bean> 到本地并解决com.google.gson.internal.LinkedTreeMap cannot be cast to异常
- The difference between new and make in golang
- 请求与响应
- BBR encounters cubic
- Arduino - character judgment function
- 一文掌握基于深度学习的人脸表情识别开发(基于PaddlePaddle)
猜你喜欢
The concepts of terminal voltage, phase voltage and line voltage in FOC vector control and BLDC control are still unclear
C MVC creates a view to get rid of the influence of layout
How can cross-border e-commerce achieve low-cost and steady growth by laying a good data base
2022年最新最全软件测试面试题大全
Interface switching based on pyqt5 toolbar button -2
golang入门:for...range修改切片中元素的值的另类方法
JDBC练习案例
Dishes launcher small green program and directory management (efficiency tool)
Realize the linkage between bottomnavigationview and navigation
Yolox enhanced feature extraction network panet analysis
随机推荐
一文掌握基于深度学习的人脸表情识别开发(基于PaddlePaddle)
Third party payment function test point [Hangzhou multi tester _ Wang Sir] [Hangzhou multi tester]
Boost库链接错误解决方案
提交代码流程
Li Kou brush questions (2022-6-28)
Implementation of VGA protocol based on FPGA
Speech recognition Series 1: speech recognition overview
RuntimeError: no valid convolution algorithms available in CuDNN
ADC of stm32
CDN acceleration requires the domain name to be filed first
Convolution和Batch normalization的融合
@How to use bindsinstance in dagger2
Alibaba cloud award winning experience: how to use polardb-x
I've been interviewed. The starting salary is 16K
A single element in an ordered array -- Valentine's Day mental problems
数据集-故障诊断:西储大学轴承的各项数据以及数据说明
Wechat applet basic learning (wxss)
Win11系统explorer频繁卡死无响应的三种解决方法
Fusion de la conversion et de la normalisation des lots
[array] binary search