Trains the technique from
LeetCode 1154Day of the YearThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
A log stamp is given as date, a string in the form "YYYY-MM-DD".
Return which day of its own year that date is, counting the first of January as day 1.
A year has 366 days when it is a leap year and 365 otherwise. A year is a leap year when it divides by 4, except that a year dividing by 100 is not a leap year unless it also divides by 400.
Example 1
The year 2020 was a leap year, so it held 366 days and its final day is day 366.
Example 2
The year 2020 divides by 4 and not by 100, so February held 29 days, putting the first of March on day 61.
Example 3
The year 1900 divides by 100 but not by 400, so it was not a leap year and February held 28 days.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def day_of_the_year(date: str) -> int:public int dayOfTheYear(String date)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.