Solved LeetCode program · 984 of 1,000
#1360 · Number of Days Between Two Dates
Original English source
Keep a shared first as empty text. Keep a shared second as empty text. Keep a shared parts as an empty list of text. Keep a shared months holding 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, and 31. Place "2020-01-15" into first. Place "2019-12-31" into second. Keep a shared amount of 0. Keep a shared leaps of 0. Keep a shared daysbefore of 0. Keep a shared yearone of 0. Keep a shared monthone of 0. Keep a shared dayone of 0. Keep a shared yeartwo of 0. Keep a shared monthtwo of 0. Keep a shared daytwo of 0.
To absorb from which (a whole number). Set amount to 0. The part is item which of parts.
For every spot from 0 to the last position of part.
The digit is the digit value of character spot of part. Set amount to amount times 10 plus digit.
To count leaps with year (a whole number). Set leaps to 0.
If year is more than 0.
Set leaps to (year minus 1) divided by 4 minus (year minus 1) divided by 100 plus (year minus 1) divided by 400.
To count days from month (a whole number) with year (a whole number). Set daysbefore to 0.
For every which from 1 to month minus 1.
Increase daysbefore by item (which minus 1) of months. If which is 2 and year modulo 4 is 0 and (year modulo 100 is not 0 or year modulo 400 is 0), add 1 to daysbefore.
Set parts to split first by "-". Absorb from 0. Set yearone to amount. Absorb from 1. Set monthone to amount. Absorb from 2. Set dayone to amount. Set parts to split second by "-". Absorb from 0. Set yeartwo to amount. Absorb from 1. Set monthtwo to amount. Absorb from 2. Set daytwo to amount.
Count leaps with yearone. Count days from monthone with yearone. The start is yearone times 365 plus leaps plus daysbefore plus dayone. Count leaps with yeartwo. Count days from monthtwo with yeartwo. The finish is yeartwo times 365 plus leaps plus daysbefore plus daytwo. The gap is the absolute value of (start minus finish).
Show gap.
Expected stdout
15