1141. 月份天数
作者:互联网
1141. 月份天数
中文English给定年份和月份,返回这个月的天数。
样例
样例 1:
输入:
2020
2
输出:
29
样例 2:
输入:
2020
3
输出:
31
注意事项
1 \leq year \leq 100001≤year≤10000
1 \leq month \leq 121≤month≤12
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]
标签:1141,return,月份,天数,31,30,month,leq,year 来源: https://www.cnblogs.com/yunxintryyoubest/p/13114490.html