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
原文地址:https://www.cnblogs.com/bernieloveslife/p/14634459.html