Algo.Java.Number of Days Between Two Dates

// https://leetcode.com/problems/number-of-days-between-two-dates/description/

    public int daysBetweenDates(String date1, String date2) {
        // Parse the input strings into LocalDate objects
        LocalDate d1 = LocalDate.parse(date1);
        LocalDate d2 = LocalDate.parse(date2);

        // Calculate the absolute difference in days
        return (int) Math.abs(ChronoUnit.DAYS.between(d1, d2));
    }
This entry was posted in Без рубрики. Bookmark the permalink.

Leave a Reply

Your email address will not be published.