题目如下:

Given a date, return the corresponding day of the week for that date.

The input is given as three integers representing the daymonth 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.

解题思路:用datetime中的strftime最简单。

代码如下:

class Solution(object):
def dayOfTheWeek(self, day, month, year):
"""
:type day: int
:type month: int
:type year: int
:rtype: str
"""
week = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]
import datetime
whatday = datetime.datetime(year, month, day).strftime("%w")
return week[int(whatday)]

【leetcode】1185. Day of the Week的更多相关文章

  1. 【LeetCode】1185. Day of the Week 解题报告(C++)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客:http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 计算与1971-1-1之间天数 日期 题目地址:htt ...

  2. 【LeetCode】Minimum Depth of Binary Tree 二叉树的最小深度 java

    [LeetCode]Minimum Depth of Binary Tree Given a binary tree, find its minimum depth. The minimum dept ...

  3. 【Leetcode】Pascal's Triangle II

    Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3, Return [1,3 ...

  4. 53. Maximum Subarray【leetcode】

    53. Maximum Subarray[leetcode] Find the contiguous subarray within an array (containing at least one ...

  5. 27. Remove Element【leetcode】

    27. Remove Element[leetcode] Given an array and a value, remove all instances of that value in place ...

  6. 【刷题】【LeetCode】007-整数反转-easy

    [刷题][LeetCode]总 用动画的形式呈现解LeetCode题目的思路 参考链接-空 007-整数反转 方法: 弹出和推入数字 & 溢出前进行检查 思路: 我们可以一次构建反转整数的一位 ...

  7. 【刷题】【LeetCode】000-十大经典排序算法

    [刷题][LeetCode]总 用动画的形式呈现解LeetCode题目的思路 参考链接 000-十大经典排序算法

  8. 【leetcode】893. Groups of Special-Equivalent Strings

    Algorithm [leetcode]893. Groups of Special-Equivalent Strings https://leetcode.com/problems/groups-o ...

  9. 【leetcode】657. Robot Return to Origin

    Algorithm [leetcode]657. Robot Return to Origin https://leetcode.com/problems/robot-return-to-origin ...

随机推荐

  1. linu基础命令1

    /根目录,第一级目录 1.ls列出当前目录下的文件和目录-a: 列出所有的文件,包括所有以.开头的隐藏文件-d: 列出目录本身,并不包含目录中的文件(-ld)-h: 和-l一起使用,文件大小人类易读 ...

  2. SVM之KKT条件理解

    在SVM中,我们的超平面参数最终只与间隔边界上的向量(样本)有关,故称为支持向量机. 求解最优超平面,即求最大化间隔,或最小化间隔的倒数:||w||2/2,约束条件为yi(wTxi+b)>=1 ...

  3. Dialupass v3.20 汉化绿色版 显示查看拨号上网密码

    Dialupass 显示查看拨号上网密码 拨号上网的密码不小心丢了怎么办?这个工具可以帮你!在紧要关头,它会让你体验到它的奇效!有备无患,快收藏这个小东东吧. 这是一款拯救忘记了拨号网络密码的使用者的 ...

  4. HDU 6175 算术

    题目大意 求 $\sum_{i = 1}^{n} \sum_{j = 1}^{m} \mu(\lcm(i, j))$ . $ 1 \le n, m \le 10^6 $ . 分析 不妨设 $ n \l ...

  5. 洛谷 P2467 地精部落 题解

    题面 好难啊好难啊好难啊~(以后再玩魔兽的时候绝对绝对虐死他) 做完后总结了一下思路; 首先推一下以下三条性质: 1.若两个 i 与 i+1 不相邻,那么我们直接交换这两个数字就可以组成一个新的数列 ...

  6. noip2015day2-运输计划

    题目描述 公元$ 2044 $年,人类进入了宇宙纪元. \(L\) 国有 \(n\) 个星球,还有 \(n-1\) 条双向航道,每条航道建立在两个星球之间,这 \(n-1\) 条航道连通了 \(L\) ...

  7. 直线的Bresenham算法

    在实验课上用自己的算法画直线被diss效率低 花了半天时间看了下Bresenham算法真

  8. AT2292 Division into Two

    题目 不妨认为\(A>B\). 首先判一下无解. 设\(f_i\)表示\(A\)集合最后选第\(i\)个数的方案数. 转移的话枚举一下从哪个\(j\)转移过来. 显然\(j\)需要满足以下条件: ...

  9. TCP和UDP头部格式的了解?

    tcp头部格式如下图所示: 1.源端口号,16位,发送方的端口号. 2.目标端口号,16位,发送方的目标端口号. 3.  32为序列号,sequence number,保证网络传输数据的顺序性. 4. ...

  10. golang 反射中调用方法

    反射中调用函数 众所周知,golang中的函数是可以像普通的int.float等类型变量那样作为值的,例如: package main import "fmt" func hell ...