【leetcode】1154. Day of the Year
题目如下:
Given a string
date
representing a Gregorian calendar date formatted asYYYY-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: 41Example 3:
Input: date = "2003-03-01"
Output: 60Example 4:
Input: date = "2004-03-01"
Output: 61Constraints:
date.length == 10
date[4] == date[7] == '-'
, and all otherdate[i]
's are digitsdate
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的更多相关文章
- 【LeetCode】1154. Day of the Year 解题报告(C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客:http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 计算1月1号之间天数 日期 题目地址:https:// ...
- 【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 ...
随机推荐
- lambda表达式使用解析
1.Predicate/Consumer/Function/Supplier介绍 Predicate boolean test(T t); Consumer accpet(T t); Function ...
- zabbix添加主机后无法显示解决
第一次添加主机后显示正常,后来删除了主机,重新添加了一下主机再也无法显示主机,很苦恼,原来需要点击重设,
- oracle-不完全数据库恢复-被动恢复-RMAN-06025/ORA-01190
不完全数据库恢复 到目前为止,前面讨论的都是完全恢复数据库,这是recover database\recover tablespace\recover datafile默认的行为特征. 所谓完全恢复指 ...
- FiddlerCore修改http返回结果
static void FiddlerApplication_BeforeRequest(Session oSession) { oSession.bBufferResponse = true; } ...
- unity shader 热扭曲 (屏幕后处理)
效果: c# using System; using System.Collections; using System.Collections.Generic; using UnityEngine ...
- python中的序列化和反序列化
~~~~~~滴滴,,什么是序列呢?可以理解为序列就是字符串.序列化的应用 写文件(数据传输) 网络传输 序列化和反序列化的概念 序列化模块:将原本的字典.列表等内容转换成一个字符串的过程就叫做序列 ...
- CNN(卷积神经网络)原理讲解及简单代码
一.原理讲解 1. 卷积神经网络的应用 分类(分类预测) 检索(检索出该物体的类别) 检测(检测出图像中的物体,并标注) 分割(将图像分割出来) 人脸识别 图像生成(生成不同状态的图像) 自动驾驶 等 ...
- python调用java所有代码都要放在jvm开启的时候调用,否则报错: No matching overloads found for in find. at native\common\jp_method.cpp:127
1.解决方法 开启java虚拟机 jvm 或者先执行结束在关闭java虚拟机jvm
- C#的Split()方法
var arr = list[i]["Tag"].Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
- vue router应用及总结
编写一个小的demo,对router基础的应用学习和理解. 效果图示: 说明: 点击About在右边显示相关信息. 说明: 点击Home,在下边显示相关信息,且Home下有两个路由链接,分别对应各自的 ...