Problema
A year divisible by 4 is a leap year unless it is also divisible by 100. Years divisible by 400 are leap years despite that exception. Apply this arithmetic rule to every allowed input year.
Implement leap_year(year).
Input
year: The year to check.
Output
Return true for a leap year and false otherwise.
Restricciones
1 ≤ year ≤ 9999.
Ejemplos
Entrada:
year = 2024
Salida esperada:
expected = True
Entrada:
long long year = 2024;
Salida esperada:
bool expected = true;
Entrada:
long year = 2024;
Salida esperada:
bool expected = true;
Explicación
2024 is divisible by 4 and not by 100.
Entrada:
year = 2100
Salida esperada:
expected = False
Entrada:
long long year = 2100;
Salida esperada:
bool expected = false;
Entrada:
long year = 2100;
Salida esperada:
bool expected = false;
Explicación
2100 is divisible by 100 but not by 400, so the century exception applies.
Cómo abordarlo
Inténtalo primero por tu cuenta y luego abre las pistas una a una.
Pista 1
Most years follow the divisible-by-4 rule, but centuries are exceptions.
Pista 2
A year divisible by 400 is still a leap year, even though it is also divisible by 100.
Pista 3
Check the exception before rejecting century years, or you may misclassify years like 2000.
Complejidad esperada
O(1) time, O(1) extra space
Referencias
Este reto está adaptado para CodeUtility. Sigue el enunciado y las restricciones indicadas arriba.