Explanation

474.Check Whether a Year Is a Leap Year

Easy
Given an integer year, return whether it is a leap year. A year is a leap year if it's divisible by 4, except century years (divisible by 100) — those are leap years only if they're also divisible by 400. (2024 is a leap year; 1900 is not; 2000 is.) The step-by-stepStep-by-Step ChecksAn if/else-if/else chain that applies the three divisibility rules one at a time, in the order that lets each one short-circuit the rest. version mirrors exactly how the rule is usually explained out loud. The single expressionSingle Boolean ExpressionCombining AND/OR directly: (div by 4 AND NOT a century year) OR (div by 400) — both ways to be a leap year, joined with no branching at all. version folds the same logic into one line using && and ||, relying on short-circuit evaluation to skip unnecessary checks.

Example 1:

Input: year = 2024

Output: true

Example 2:

Input: year = 1900

Output: false

Example 3:

Input: year = 2000

Output: true

+ 6 hidden test cases run on Submit.

Constraints:

  • ●1 ≤ year ≤ 9999

year =

2024