Determine if a given year is a leap year. A year is a leap year if it follows these rules:
- The year must be divisible by 4
- However, if the year is divisible by 100, it is NOT a leap year
- Unless the year is also divisible by 400, then it IS a leap year
Return true if the year is a leap year, false otherwise. Return false for null input.
Examples
Example 1:
Input: 2024
Output: true
Explanation: 2024 is divisible by 4 but not by 100, so it is a leap year.
Example 2:
Input: 1900
Output: false
Explanation: 1900 is divisible by 100 but not by 400, so it is not a leap year.
Example 3:
Input: 2000
Output: true
Explanation: 2000 is divisible by 400, so it is a leap year.
Example 4:
Input: 2023
Output: false
Explanation: 2023 is not divisible by 4, so it is not a leap year.
Example 5:
Input: null
Output: false
Explanation: Null input should return false.
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 July 2026
Contest runs July 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.