Leetcode Note: Go - Number of Days Between Two Dates

Number of Days Between Two Dates - LeetCode
https://leetcode.com/problems/number-of-days-between-two-dates/

  • Go 言語で取り組んだメモ

回答

Go | Time: O(1) / 0 ms / 100% | Space: O(1) / 2.1 MB / 33.33% - Number of Days Between Two Dates - LeetCode
https://leetcode.com/problems/number-of-days-between-two-dates/solutions/1548007/go-time-o-1-0-ms-100-space-o-1-2-1-mb-33-33/

func daysBetweenDates(date1 string, date2 string) int {
    t1, _ := time.Parse(time.RFC3339, date1 + "T00:00:00.000Z")
    t2, _ := time.Parse(time.RFC3339, date2 + "T00:00:00.000Z")
    
    return int(math.Abs(t2.Sub(t1).Hours() / 24))
}