0
Leetcode Problem 1118. Number of Days in a Month
1118. Number of Days in a Month
AI Mock Interview
Leetcode Solutions
Calculating Days in a Month with Leap Year Check
Solution Idea
Algorithm Steps
Code Implementation
Complexity Analysis
Create an array
monthDays
with the number of days for each month, where February has 28 days by default.
Check if the month is February (month == 2).
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.
If it is a leap year and the month is February, return 29 days.
If it is not February or not a leap year, return the number of days from the
monthDays
array for the given month.
Using Python's calendar module
Ask Question
Programming Language
Purpose:
General Question
Debug My Code
image/screenshot of info
(optional)
[+]
Full Screen
Loading...
Get Answer
Suggested Answer
Answer
Full Screen
Copy Answer Code
Loading...