zoukankan      html  css  js  c++  java
  • [Swift]LeetCode1118. 一月有多少天 | Number of Days in a Month

    ★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★
    ➤微信公众号:山青咏芝(shanqingyongzhi)
    ➤博客园地址:山青咏芝(https://www.cnblogs.com/strengthen/
    ➤GitHub地址:https://github.com/strengthen/LeetCode
    ➤原文地址:https://www.cnblogs.com/strengthen/p/11179554.html 
    ➤如果链接不是山青咏芝的博客园地址,则可能是爬取作者的文章。
    ➤原文已修改更新!强烈建议点击原文地址阅读!支持作者!支持原创!
    ★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★

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

    Example 1:

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

    Example 2:

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

    Example 3:

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

    Note:

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

    指定年份 Y 和月份 M,请你帮忙计算出该月一共有多少天。 

    示例 1:

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

    示例 2:

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

    示例 3:

    输入: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 }
  • 相关阅读:
    pip安装
    nfs
    源码方式安装软件
    自启动
    multipath
    linux永久添加和删除路由
    iscsi
    linux识别workstation磁盘的uuid
    centos镜像各种cd,dvd版本区别
    转:C# 中 MSCHART 饼状图显示百分比
  • 原文地址:https://www.cnblogs.com/strengthen/p/11179554.html
Copyright © 2011-2022 走看看