bugfree Icon
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course

Leetcode Problem 1118. Number of Days in a Month

1118. Number of Days in a Month

Leetcode Solutions

Calculating Days in a Month with Leap Year Check

  1. Create an array monthDays with the number of days for each month, where February has 28 days by default.
  2. Check if the month is February (month == 2).
  3. If it is February, determine if the year is a leap year by checking the following conditions:
    • If the year is divisible by 4 but not by 100, or
    • If the year is divisible by 400.
  4. If it is a leap year and the month is February, return 29 days.
  5. If it is not February or not a leap year, return the number of days from the monthDays array for the given month.
UML Thumbnail

Using Python's calendar module

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...