当前位置:网站首页>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 !
边栏推荐
- Arduino - 字符判断函数
- JDBC練習案例
- Golang common settings - modify background
- Solution to boost library link error
- BBR encounters cubic
- 基于Pyqt5工具栏按钮可实现界面切换-1
- Is 408 not fragrant? The number of universities taking the 408 examination this year has basically not increased!
- Go basic constant definition and use
- Bean load control
- Load balancing cluster (LBC)
猜你喜欢

What experience is there only one test in the company? Listen to what they say

购买完域名之后能干什么事儿?

How can cross-border e-commerce achieve low-cost and steady growth by laying a good data base

2022年最新最全软件测试面试题大全

Catalogue of digital image processing experiments
![[analysis of STL source code] imitation function (to be supplemented)](/img/40/a02a04a24f385a31e0484d1071ecec.jpg)
[analysis of STL source code] imitation function (to be supplemented)

Explain promise usage in detail

Cryptography -- the mode of block cipher

跨境电商如何通过打好数据底座,实现低成本稳步增长

What can I do after buying a domain name?
随机推荐
What if win11 can't turn off the sticky key? The sticky key is cancelled but it doesn't work. How to solve it
富滇银行完成数字化升级|OceanBase数据库助力布局分布式架构中台
采用VNC Viewer方式远程连接树莓派
[Verilog tutorial]
基于Pyqt5工具栏按钮可实现界面切换-1
[error record] the flutter reports an error (could not resolve io.flutter:flutter_embedding_debug:1.0.0.)
Alibaba cloud award winning experience: how to use polardb-x
vim区间删行注释
"A good programmer is worth five ordinary programmers!"
CDN 加速,需要域名先备案
提交代码流程
Go project operation method
【ML】李宏毅三:梯度下降&分类(高斯分布)
Pandora IOT development board learning (HAL Library) - Experiment 4 serial port communication experiment (learning notes)
4 special cases! Schools in area a adopt the re examination score line in area B!
golang入门:for...range修改切片中元素的值的另类方法
All things work together, and I will review oceanbase's practice in government and enterprise industry
Redis expiration policy +conf record
FOC矢量控制及BLDC控制中的端电压、相电压、线电压等概念别还傻傻分不清楚
Getting started with golang: for Range an alternative method of modifying the values of elements in slices