Given a year, return the number of days in that year. A leap year has 366 days; a common year has 365 days.
Leap year rules:
- A year divisible by 4 is a leap year
- EXCEPT: years divisible by 100 are NOT leap years
- UNLESS: the year is also divisible by 400, in which case it IS a leap year
If year is null, return null.
Example 1:
Input: year = 2024
Output: 366
Explanation: 2024 is divisible by 4 and not a century year, so it is a leap year
Example 2:
Input: year = 2023
Output: 365
Explanation: 2023 is not divisible by 4, so it is a common year
Example 3:
Input: year = 2000
Output: 366
Explanation: 2000 is divisible by 400, so it is a leap year despite being a century
Example 4:
Input: year = 1900
Output: 365
Explanation: 1900 is divisible by 100 but not by 400, so it is not a leap year
Example 5:
Input: year = null
Output: null
Apex Code Editor
Welcome to Lightning Challenge!
How It Works
- • Write your solution in the code editor
- • Connect your Salesforce org to test
- • Submit to check if your solution passes
- • Use hints if you get stuck
Contest Alert
🏆 #CodeEveryDay August 2026
Contest runs August 1 - 31. Complete challenges to climb the leaderboard!
Only the 31 daily challenges shown during this contest count toward points. Earlier dailies don't carry over.