【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 ...
随机推荐
- 使用xUnits来实现单元测试
目录 前言 单元测试 xUnit 小结 附录 前言 从开始敲代码到现在,不停地都是在喊着记得做测试,记得自测,测试人员打回来扣你money之类的,刚开始因为心疼钱(当然还是为了代码质量),就老老实实自 ...
- 【HANA系列】SAP HANA跟我学HANA系列之创建分析视图一
公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:[HANA系列]SAP HANA跟我学HANA系 ...
- Matlab学习笔记1—MATLAB基础知识
1.1 MATLAB系统环境 1.MATLAB操作界面的组成 (1)MATLAB主窗口 (2)命令行窗口:命令行窗口用于输入命令并显示命令的执行结果. (3) 当前文件夹窗口 如何设置当前文件夹呢? ...
- 交换机安全学习笔记 第四章 VLAN
Trunk 口 思科称为:native VLAN 华为称为:PVID 说白了就是Trunk端口本身所属的VLAN,因为,Trunk端口要"透传"多个VLAN的流量,其本 ...
- vue-loader介绍和单页组件介绍
$ \es6\sing-file> npm install vue-loader@14.1.1 -D vue-template-compiler@2.5.17 -D npm install v ...
- 关于float的小奥秘
一. float 存储方式 1.1. float 占四个字节 1.2. 浮点数构成 1.2.1. 无论是单精度还是双精度在存储中都分为三个部分: <1>. 符号位(Sign) : 0代表正 ...
- windows 通过cmd命令行管理防火墙
(1)恢复初始防火墙设置 netsh advfirewall reset(2)关闭防火墙 netsh advfirewall set allprofiles state off(3)启用桌面防火墙 n ...
- Git_初步了解
Git入门篇 一:Git是什么?Git是目前世界上最先进的分布式版本控制系统.工作原理 / 流程: Workspace:工作区Index / Stage:暂存区Repository:仓库区(或本地仓库 ...
- vue 实践技巧合集
前言 本文纯属个人平时实践过程中的一些经验总结,算是一点点小技巧吧,不是多么高明的技术,如果对你有帮助,那么不胜荣幸. 本文不涉及罕见API使用方法等,大部分内容都是基于对vue的一些实践而已.由于涉 ...
- go语言中os/signal包的学习与使用
package main; import ( "os" "os/signal" "fmt" ) //signal包中提供了两个函数 //No ...