• 1141 · 月份天数


    描述
    给定年份和月份,返回这个月的天数。

    1 leq year leq 100001≤year≤10000
    1 leq month leq 121≤month≤12

    样例
    样例 1:

    输入:
    2020
    2
    输出:
    29
    样例 2:

    输入:
    2020
    3
    输出:
    31

    class Solution:
        """
        @param year: a number year
        @param month: a number month
        @return: Given the year and the month, return the number of days of the month.
        """
        def getTheMonthDays(self, year, month):
            days = [0,31,0,31,30,31,30,31,31,30,31,30,31]
            is_leap_year = False
            if year%400 == 0 or (year%100!=0 and year%4 == 0):
                is_leap_year = True
            return days[month] if month!=2 else 29 if is_leap_year else 28
    
  • 相关阅读:
    hdu 1286
    hdu 1420
    hdu 2068
    hdu 1718
    hdu 1231
    hdu 1072
    HDOJ 350留念
    hdu 1898
    hdu 1593
    帮助理解git的图
  • 原文地址:https://www.cnblogs.com/bernieloveslife/p/14634459.html
Copyright © 2020-2023  润新知