给你一个日期,请你设计一个算法来判断它是对应一周中的哪一天。
输入为三个整数:day、month 和 year,分别表示日、月、年。
您返回的结果必须是这几个值中的一个 {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"}。
来源:力扣(LeetCode)
链接:https://leetcode-cn.com/problems/day-of-the-week
著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。
Python 调包版本
import datetime class Solution: def dayOfTheWeek(self, day: int, month: int, year: int) -> str: week = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday","Sunday", ] return week[datetime.date(year,month,day).weekday()]
Python 版本
C++ 版本
https://www.pynote.net/archives/445