【leetcode】1185. Day of the Week
题目如下:
Given a date, return the corresponding day of the week for that date.
The input is given as three integers representing the
day,monthandyearrespectively.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
1971and2100.
解题思路:用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的更多相关文章
- 【LeetCode】1185. Day of the Week 解题报告(C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客:http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 计算与1971-1-1之间天数 日期 题目地址:htt ...
- 【LeetCode】Minimum Depth of Binary Tree 二叉树的最小深度 java
[LeetCode]Minimum Depth of Binary Tree Given a binary tree, find its minimum depth. The minimum dept ...
- 【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 ...
- 53. Maximum Subarray【leetcode】
53. Maximum Subarray[leetcode] Find the contiguous subarray within an array (containing at least one ...
- 27. Remove Element【leetcode】
27. Remove Element[leetcode] Given an array and a value, remove all instances of that value in place ...
- 【刷题】【LeetCode】007-整数反转-easy
[刷题][LeetCode]总 用动画的形式呈现解LeetCode题目的思路 参考链接-空 007-整数反转 方法: 弹出和推入数字 & 溢出前进行检查 思路: 我们可以一次构建反转整数的一位 ...
- 【刷题】【LeetCode】000-十大经典排序算法
[刷题][LeetCode]总 用动画的形式呈现解LeetCode题目的思路 参考链接 000-十大经典排序算法
- 【leetcode】893. Groups of Special-Equivalent Strings
Algorithm [leetcode]893. Groups of Special-Equivalent Strings https://leetcode.com/problems/groups-o ...
- 【leetcode】657. Robot Return to Origin
Algorithm [leetcode]657. Robot Return to Origin https://leetcode.com/problems/robot-return-to-origin ...
随机推荐
- LeetCode.927-独特邮箱地址(Unique Email Addresses)
这是悦乐书的第356次更新,第383篇原创 01看题和准备 今天介绍的是LeetCode算法题中Easy级别的第218题(顺位题号是927).每封电子邮件都包含本地名称和域名,以@符号分隔. 例如,在 ...
- HCL试验3
PC端配置:配置ip地址 配置网关 交换机(左)配置:①创建VLAN system-view vlan 10 vlan 20 ②配置PC端接口 interface gi 1/0/1 port link ...
- HDU2196 Computer【换根dp】
题目传送门 题意: 给定一个$N$个点的树,第$i$条边的长度是$A_i$,求每个点到其他所有点的最长距离.数据范围:$n ≤ 10000$,$A_i ≤ 10_9$ 分析 首先,从随便哪个节点($1 ...
- 在Bean中获取spring 容器 并通过容器获取容器中其他bean
spring 提供了Awear 接口去 让bean 能感受到外界的环境.Awear 接口有很多实现,常用的有 ApplicationContextAware (可以通过实现这个接口去获取Applica ...
- Spark中的术语图解总结
参考:http://www.raincent.com/content-85-11052-1.html 1.Application:Spark应用程序 指的是用户编写的Spark应用程序,包含了Driv ...
- Maven build 命令介绍(转)
常用命令: 打包:mvn package编译:mvn compile清空:mvn clean(清除编译后目录,默认是target目录)运行测试:mvn test安装jar包到本地仓库中:mvn ins ...
- python-event事件-模仿红绿灯
import time import threading event =threading.Event() def lighter(): count=0 event.set()#先设置成绿灯 whil ...
- Qt3D 设置窗口背景颜色和图案
目录 设置窗口的颜色 复杂背景的设置 最近在用 Qt3D 做三维显示,需要设置窗口Qt3DWindow背景的颜色, 查了一些资料,做一些整理,备查. 设置窗口的颜色 如果只是最简单的需求设置某一种颜色 ...
- centos安装mysql以及授权登录用户
CentOS第一次安装MySQL的完整步骤 目录 1.官方安装文档 2.下载 Mysql yum包 3.安转软件源 4.安装mysql服务端 5.首先启动mysql ...
- springboot在集成mybatis的时候老是报错 The server time zone value '�й���ʱ��' is unrecognized
我已经解决了,感谢万能网友. 解决办法参见:https://blog.csdn.net/yunfeng482/article/details/86698133