当前位置:网站首页>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 !
边栏推荐
- 20220527_ Database process_ Statement retention
- Win11系统explorer频繁卡死无响应的三种解决方法
- 第三方支付功能测试点【杭州多测师_王sir】【杭州多测师】
- Third party payment function test point [Hangzhou multi tester _ Wang Sir] [Hangzhou multi tester]
- SharedPreferences 保存List<Bean> 到本地并解决com.google.gson.internal.LinkedTreeMap cannot be cast to异常
- 跨境电商如何通过打好数据底座,实现低成本稳步增长
- cocospods 的使用
- C MVC creates a view to get rid of the influence of layout
- 4 special cases! Schools in area a adopt the re examination score line in area B!
- [Verilog tutorial]
猜你喜欢

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

LINQ usage collection in C #

采用VNC Viewer方式遠程連接樹莓派

Why can't the start method be called repeatedly? But the run method can?

Go basic constant definition and use

Potplayer set minimized shortcut keys

Master the development of facial expression recognition based on deep learning (based on paddlepaddle)

Getting started with golang: for Range an alternative method of modifying the values of elements in slices

基于FPGA的VGA协议实现

RuntimeError: no valid convolution algorithms available in CuDNN
随机推荐
采用VNC Viewer方式远程连接树莓派
2022 latest and complete interview questions for software testing
理想汽车×OceanBase:当造车新势力遇上数据库新势力
Go basic data type
Solution: exceptiole 'xxxxx QRTZ_ Locks' doesn't exist and MySQL's my CNF file append lower_ case_ table_ Error message after names startup
Realize the linkage between bottomnavigationview and navigation
Alibaba cloud award winning experience: how to use polardb-x
潘多拉 IOT 开发板学习(HAL 库)—— 实验3 按键输入实验(学习笔记)
JSON data transfer parameters
公司里只有一个测试是什么体验?听听他们怎么说吧
"A good programmer is worth five ordinary programmers!"
Hisilicon VI access video process
Pandora IOT development board learning (HAL Library) - Experiment 3 key input experiment (learning notes)
What experience is there only one test in the company? Listen to what they say
What can I do after buying a domain name?
Bean加载控制
【直播预约】数据库OBCP认证全面升级公开课
程序分析与优化 - 9 附录 XLA的缓冲区指派
[error record] the flutter reports an error (could not resolve io.flutter:flutter_embedding_debug:1.0.0.)
Redis expiration policy +conf record