首页 > 其他 > 详细

1141 · 月份天数

时间:2021-04-08 20:41:56      阅读:24      评论:0      收藏:0      [点我收藏+]

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

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

1141 · 月份天数

原文:https://www.cnblogs.com/bernieloveslife/p/14634459.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!