题目地址:https://leetcode.com/problems/day-of-the-year/

题目描述

Given a year Y and a month M, return how many days there are in that month.

Example 1:

Input: Y = 1992, M = 7
Output: 31

Example 2:

Input: Y = 2000, M = 2
Output: 29

Example 3:

Input: Y = 1900, M = 2
Output: 28

Note:

  1. 1583 <= Y <= 2100
  2. 1 <= M <= 12

题目大意

判断给出的某年某月有多少天。

解题方法

判断是否是闰年

这个题和1185. Day of the Week类似。

这个题中计算出当年是不是闰年,然后从数组中读取当月的天数。

C++代码如下:

class Solution {
public:
int numberOfDays(int Y, int M) {
return daysOfMonth[isLeapYear(Y)][M - 1];
}
bool isLeapYear(int year) {
return (year % 4 == 0 && year % 100 != 0) || year % 400 == 0;
}
int daysOfMonth[2][12] = {
{31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31},
{31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}
};
};

日期

2019 年 9 月 18 日 —— 今日又是九一八

【LeetCode】1118. Number of Days in a Month 解题报告(C++)的更多相关文章

  1. LeetCode 806 Number of Lines To Write String 解题报告

    题目要求 We are to write the letters of a given string S, from left to right into lines. Each line has m ...

  2. 【LeetCode】452. Minimum Number of Arrows to Burst Balloons 解题报告(Python)

    [LeetCode]452. Minimum Number of Arrows to Burst Balloons 解题报告(Python) 标签(空格分隔): LeetCode 题目地址:https ...

  3. 【LeetCode】129. Sum Root to Leaf Numbers 解题报告(Python)

    [LeetCode]129. Sum Root to Leaf Numbers 解题报告(Python) 标签(空格分隔): LeetCode 题目地址:https://leetcode.com/pr ...

  4. 【LeetCode】380. Insert Delete GetRandom O(1) 解题报告(Python)

    [LeetCode]380. Insert Delete GetRandom O(1) 解题报告(Python) 作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxu ...

  5. 【LeetCode】873. Length of Longest Fibonacci Subsequence 解题报告(Python)

    [LeetCode]873. Length of Longest Fibonacci Subsequence 解题报告(Python) 标签(空格分隔): LeetCode 作者: 负雪明烛 id: ...

  6. 【LeetCode】423. Reconstruct Original Digits from English 解题报告(Python)

    [LeetCode]423. Reconstruct Original Digits from English 解题报告(Python) 标签: LeetCode 题目地址:https://leetc ...

  7. 【LeetCode】Longest Word in Dictionary through Deleting 解题报告

    [LeetCode]Longest Word in Dictionary through Deleting 解题报告 标签(空格分隔): LeetCode 题目地址:https://leetcode. ...

  8. 【LeetCode】718. Maximum Length of Repeated Subarray 解题报告(Python)

    [LeetCode]718. Maximum Length of Repeated Subarray 解题报告(Python) 标签(空格分隔): LeetCode 作者: 负雪明烛 id: fuxu ...

  9. 【LeetCode】201. Bitwise AND of Numbers Range 解题报告(Python)

    [LeetCode]201. Bitwise AND of Numbers Range 解题报告(Python) 标签: LeetCode 题目地址:https://leetcode.com/prob ...

随机推荐

  1. 基于PASA进行基因预测

    PASA, acronym for Program to Assemble Spliced Alignments, is a eukaryotic genome annotation tool tha ...

  2. 68-Binary Tree Postorder Traversal

    Binary Tree Postorder Traversal My Submissions QuestionEditorial Solution Total Accepted: 97358 Tota ...

  3. SQL-join(inner join)、left join、right join、full join

    0.JOIN 类型 有时我们需要从两个或更多的表中获取结果,数据库中的表可通过键将彼此联系起来.每个表中都有一个主键,主键(Primary Key)是一个列,值都唯一.这样做的目的是在不重复每个表中的 ...

  4. LightningChart JS v.3.3.0全新版本现已发布!

    LightningChart JS v.3.3.0已经发布啦!!! 欢迎了解更多关于最新的性能改进.新的用户界面功能和新的图表类型的信息! WebGL兼容性和新的UI功能 WebGL是Lightnin ...

  5. 【NetCore】RabbitMQ 封装

    RabbitMQ 封装 代码 https://gitee.com/wosperry/wosperry-rabbit-mqtest/tree/master 参考Abp事件总线的用法,对拷贝的Demo进行 ...

  6. typedef定义数组

    typedef定义数组 问题来源 在学习高一凡数据结构与算法解析串这一章节时,遇到如下代码不明白其意义,经过查阅终于搞明白 typedef unsigned char SString[MAXLEN + ...

  7. 用前端表格技术构建医疗SaaS 解决方案

    电子健康档案(Electronic Health Records, EHR)是将患者在所有医疗机构产生的数据(病历.心电图.医疗影像等)以电子化的方式存储,通过在不同的医疗机构之间共享,让患者面对不同 ...

  8. 我可以减肥失败,但我的 Docker 镜像一定要瘦身成功!

    作者|徐伟 来源|尔达 Erda 公众号 ​ 简介 容器镜像类似于虚拟机镜像,封装了程序的运行环境,保证了运行环境的一致性,使得我们可以一次创建任意场景部署运行.镜像构建的方式有两种,一种是通过 do ...

  9. MySQL索引背后的数据结构及算法原理 【转】

    摘要 本文以MySQL数据库为研究对象,讨论与数据库索引相关的一些话题.特别需要说明的是,MySQL支持诸多存储引擎,而各种存储引擎对索引的支持也各不相同,因此MySQL数据库支持多种索引类型,如BT ...

  10. Android Handler 消息机制原理解析

    前言 做过 Android 开发的童鞋都知道,不能在非主线程修改 UI 控件,因为 Android 规定只能在主线程中访问 UI ,如果在子线程中访问 UI ,那么程序就会抛出异常 android.v ...