在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★ Given a year Example 1: Input: Y = 7
Output: 31
Example 2: Input: Y = 2
Output: 29
Example 3: Input: Y = 2
Output: 28
Note:
指定年份 示例 1: 输入:Y = 1992, M = 7 输出:31 示例 2: 输入:Y = 2000, M = 2 输出:29 示例 3: 输入:Y = 1900, M = 2 输出:28 提示:
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 }
|
请发表评论