leetcode1185

package
v0.0.0-...-a94f1ba Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 22, 2024 License: BSD-3-Clause Imports: 1 Imported by: 0

README

Day of the Week

基姆拉尔森计算公式(Kim larsson calculation formula)

w = (day + 2month + 3(month+1)/5 + year + year/4 - year/100 + year/400 + 1) % 7

0 表示周日。把一月和二月看成是上一年的十三月和十四月。

基姆拉尔森计算公式 推导

天数累计模 7

1971/01/01 是周五,那么第零天的累计量是 4。
累计年份天数,再累计月份天数,再加上最后一个月天数,最后加上偏移量 4。

Documentation

Overview

* @lc app=leetcode id=1185 lang=golang * * [1185] Day of the Week * * https://leetcode.com/problems/day-of-the-week/description/ * * algorithms * Easy (64.33%) * Likes: 58 * Dislikes: 686 * Total Accepted: 14.4K * Total Submissions: 22.3K * Testcase Example: '31\n8\n2019' * * Given a date, return the corresponding day of the week for that date. * * The input is given as three integers representing the day, month and year * respectively. * * Return the answer as one of the following 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" * * * * Constraints: * * * The given dates are valid dates between the years 1971 and 2100. *

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL