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]

 

相关文章:

  • 2022-12-23
  • 2021-08-09
  • 2021-07-19
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-02-05
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-04-07
  • 2022-12-23
  • 2022-12-23
  • 2021-09-23
  • 2021-06-10
相关资源
相似解决方案