题目如下:

Given a string date representing a Gregorian calendar date formatted as YYYY-MM-DD, return the day number of the year.

Example 1:

Input: date = "2019-01-09"
Output: 9
Explanation: Given date is the 9th day of the year in 2019.

Example 2:

Input: date = "2019-02-10"
Output: 41

Example 3:

Input: date = "2003-03-01"
Output: 60

Example 4:

Input: date = "2004-03-01"
Output: 61

Constraints:

  • date.length == 10
  • date[4] == date[7] == '-', and all other date[i]'s are digits
  • date represents a calendar date between Jan 1st, 1900 and Dec 31, 2019.

解题思路:题目很简单,注意区分闰年和平年即可。

代码如下:

class Solution(object):
def dayOfYear(self, date):
"""
:type date: str
:rtype: int
"""
date = date.split('-')
year = date[0]
def isLeapYear(year):
return (year % 4) == 0 and (year % 100) != 0 or (year % 400) == 0
month_list = [31,28,31,30,31,30,31,31,30,31,30,31]
if isLeapYear(int(year)):
month_list[1] += 1
month = int(date[1])
return sum(month_list[:month-1]) + int(date[2])

【leetcode】1154. Day of the Year的更多相关文章

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

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

  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. 【命令汇总】nmap 使用教程

    日期:2019-07-03 21:23:39 更新: 作者:Bay0net 介绍:汇总一下笔记里面的 nmap 使用方式 0x01. 基本信息 Nmap: the Network Mapper - F ...

  2. 系统分析与设计HW1

    软件工程的定义 1993年,电气电子工程师学会(IEEE)给出了一个定义:"将系统化的.规范的.可度量的方法用于软件的开发.运行和维护的过程,即将工程化应用于软件开发中". 阅读经 ...

  3. oracle-只读数据文件的备份与恢复

    11 只读数据文件的备份与恢复 只读数据文件是只读表空间的数据文件,数据块包括文件头在内部允许更改 SQL> alter tablespace yhqt read only; SQL> a ...

  4. 远程桌面 虚拟打印 到本地打印机(虚拟化 终端 远程接入 RemoteApp)

    使用远程桌面或remoteapp进行打印时,若需使用本地的打印机,需要通过重定向方式,但本地打印机如果五花八门比较杂,那给服务器安装打印机驱动很麻烦. 其实可以借助虚拟打印机简化操作,省去给服务器安装 ...

  5. 无法获得锁 /var/lib/dpkg/lock-frontend - open (11: 资源暂时不可用)

    ubuntu更新软件时 apt-get upgrade 遇到 E: 无法获得锁 /: 资源暂时不可用) E: Unable to acquire the dpkg frontend lock (/va ...

  6. kafka学习(七)

    跨集群数据镜像 跨集群镜像的使用场景 1.区域集群和中心集群 2.冗余,发生紧急情况下使用第二个集群,保存相同的数据. 3.云迁移   多集群架构   跨集群中心通信的一些现实情况 1.高延迟 2.有 ...

  7. jenkins自动化测试Email Extension邮件模板 及可用参数TEST_COUNTS ,FAILED_TESTS详细说明

    先列出模板内容: <!DOCTYPE html><html> <head> <meta charset="UTF-8"> <t ...

  8. 教你在 IntelliJ IDEA 中使用 VIM!

    Java技术栈 www.javastack.cn 优秀的Java技术公众号 IdeaVim(下载)插件可以让你在IntelliJ IDEA中键盘敲的飞起. 安装 打开IDEA的设置,在Plugins里 ...

  9. P3951小凯的疑惑

    这是2017年提高组的第一题,是一个小学奥数题?听说很多大佬爆零了,我AC了,,, 这个题首先给出两个素数,问取任意个这两个素数之和不可以达到的最大的数是多少?拿到这个题首先很蒙,于是试了试样例,并没 ...

  10. 基类子类在Qt信号量机制下的思考

    背景知识: 基类 superClass class superClass { public: superClass() { std::string m = "superClass() &qu ...