[Swift]LeetCode1118. 一月有多少天 | Number of Days in a Month

★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★
➤微信公衆號:山青詠芝(shanqingyongzhi)
➤博客園地址:山青詠芝(https://www.cnblogs.com/strengthen/
➤GitHub地址:https://github.com/strengthen/LeetCode
➤原文地址:http://www.javashuo.com/article/p-fyjcqdeb-kx.html 
➤若是連接不是山青詠芝的博客園地址,則多是爬取做者的文章。
➤原文已修改更新!強烈建議點擊原文地址閱讀!支持做者!支持原創!
★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★html

Given a year Y and a month M, return how many days there are in that month. git

Example 1:github

Input: Y = 1992, M = 7 Output: 31 

Example 2:微信

Input: Y = 2000, M = 2 Output: 29 

Example 3:spa

Input: Y = 1900, M = 2 Output: 28 

Note:code

  1. 1583 <= Y <= 2100
  2. 1 <= M <= 12

指定年份 Y 和月份 M,請你幫忙計算出該月一共有多少天。 htm

示例 1:blog

輸入:Y = 1992, M = 7
輸出:31

示例 2:get

輸入:Y = 2000, M = 2
輸出:29

示例 3:input

輸入:Y = 1900, M = 2
輸出:28 

提示:

  1. 1583 <= Y <= 2100
  2. 1 <= M <= 12

4ms

 1 class Solution {
 2     func numberOfDays(_ Y: Int, _ M: Int) -> Int {
 3         if Y % 400 == 0 || (Y % 100 != 0 && Y % 4 == 0)
 4         {
 5             if M == 2 {return 29}
 6         }
 7         let mon:[Int] = [31,28,31,30,31,30,31,31,30,31,30,31]
 8         return mon[M - 1]
 9     }
10 }
相關文章
相關標籤/搜索