1141. 月份天数

1141. 月份天数

中文English

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

样例

样例 1:

输入: 
2020 
2
输出: 
29

样例 2:

输入: 
2020 
3
输出: 
31

注意事项

1 \leq year \leq 100001year10000
1 \leq month \leq 121month12

 
 
输入测试数据 (每行一个参数)如何理解测试数据?
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):
        # write your code here
        normal_months = [0,31,28,31,30,31,30,31,31,30,31,30,31]
        leap_months = [0,31,29,31,30,31,30,31,31,30,31,30,31]
        #判断是否闰年
        def isLeapYear(year):
            return year % 4 == 0 and (year % 100 != 0 or year % 400 == 0)
        
        return leap_months[month] if isLeapYear(year) else normal_months[month]

 

posted @ 2020-06-13 14:51  风不再来  阅读(194)  评论(0编辑  收藏  举报