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!
Create an Account
Sign up to track your progress, earn points, and compete with others. Your solutions will be saved automatically.
Create accountHow 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
Note
You can test your code by connecting to Salesforce, but to save your progress and earn points, you'll need to create an account. Your solutions and achievements will be tracked automatically once you're logged in.