Notice
Recent Posts
Recent Comments
Link
.Zzumbong
[leetCode/JS] 1360. Number of Days Between Two Dates 본문
문제 설명
Write a program to count the number of days between two dates.
The two dates are given as strings, their format is YYYY-MM-DD
as shown in the examples.
입출력 예
Example 1:
Input: date1 = "2019-06-29", date2 = "2019-06-30"
Output: 1
Example 2:
Input: date1 = "2020-01-15", date2 = "2019-12-31"
Output: 15
Constraints
- The given dates are valid dates between the years
1971
and2100
.
내 솔루션
- 차이 나는 일자를 리턴하는 간단한 함수.
var daysBetweenDates = function(date1, date2) {
const time = new Date(date2) - new Date(date1);
return Math.abs(time / 1000 / 60 / 60 / 24)
};
감상평
- 쉬웠다. 하지만 많이 쓰이는 함수
'coding test > leetCode' 카테고리의 다른 글
[leetCode/JS] 587. Erect the Fence (0) | 2022.11.23 |
---|---|
[leetCode/JS] 696. Count Binary Substrings (0) | 2022.11.23 |
[leetCode/JS] 263. Ugly Number (0) | 2022.11.23 |
[leetCode/JS] 223. Rectangle Area (0) | 2022.11.23 |
[leetCode/JS] 1975. Maximum Matrix Sum (0) | 2022.11.23 |
0 Comments