【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: 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 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 ...
随机推荐
- Linux_SystemLogManager
目录 目录 前言 日志管理journalctl工具 日志服务属性 自定义日志 journalctl 指令 前言 还是RHEL7的新特性,引入了journalctl指令作为系统日志的管理工具. 日志管理 ...
- JMV监控工具之JConsole
一.简介 JConsole是一个基于JMX的GUI工具,用于连接正在运行的JVM,它是Java自带的简单性能监控工具.下面以对tomcat的监控为例,带领大家熟悉JConsole这个工具. 二.配置 ...
- 郝斌_GUI
85事件处理 import java.awt.Button; import java.awt.Frame; import java.awt.event.ActionEvent; import java ...
- springmvc中获取request对象,加载biz(service)的方法
获取request对象: 首先配置web.xml文件--> <listener> <listener-class> org.springframework.web.con ...
- 干货 | 剑指offer系列文章汇总
下面是名企面试中经常会出现的面试题目,大家可以戳相应的题目查看题目细节,其答案会在紧接着的后一篇中出现 剑指offer系列 始 剑指offer—灯管问题(1) 剑指offer—10人电梯(2) ...
- 简述Vue的路由与视图
1.vue-router 安装方式 npm/cnpm:(个人偏向于cnpm) npm/cnpm install vue-router --save-dev bower: bower install v ...
- 获取kafka最新offset-scala
无论是在spark streaming消费kafka,或是监控kafka的数据时,我们经常会需要知道offset最新情况 kafka数据的topic基于分区,并且通过每个partition的主分区可以 ...
- Dubbo 序列化协议 5 连问,你接得住不?
1)dubbo 支持哪些通信协议? 2)支持哪些序列化协议? 3)说一下 Hessian 的数据结构? 4)PB 知道吗? 5)为什么 PB 的效率是最高的? 面试官心理分析 上一个问题,说说 dub ...
- 编写Servlet步骤以及Servlet生命周期是怎样的
一.编写Servlet步骤 1.继承HttpServlet,HttpServlet在javax-servlet-api依赖下 2.重写doGet()或者doPost()方法 3.在web.xml中注册 ...
- osi七层模型??
1.应用层:提供用户服务,例如处理应用程序,文件传输,数据管理 (HTTP.RTSP.FTP) 2.表示层:做数据的转换和压缩,加解密等 3.会话层:决定了进程间的连接建立,选择使用什么样的 ...