Skip to content

Commit 0071f79

Browse files
committedDec 4, 2021
Add solution #1507
1 parent 8e27e22 commit 0071f79

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed
 

‎README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@
177177
1493|[Longest Subarray of 1's After Deleting One Element](./1493-longest-subarray-of-1s-after-deleting-one-element.js)|Medium|
178178
1496|[Path Crossing](./1496-path-crossing.js)|Easy|
179179
1502|[Can Make Arithmetic Progression From Sequence](./1502-can-make-arithmetic-progression-from-sequence.js)|Easy|
180+
1507|[Reformat Date](./1507-reformat-date.js)|Easy|
180181
1598|[Crawler Log Folder](./1598-crawler-log-folder.js)|Easy|
181182
1780|[Check if Number is a Sum of Powers of Three](./1780-check-if-number-is-a-sum-of-powers-of-three.js)|Medium|
182183
1880|[Check if Word Equals Summation of Two Words](./1880-check-if-word-equals-summation-of-two-words.js)|Easy|

‎solutions/1507-reformat-date.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/**
2+
* 1507. Reformat Date
3+
* https://leetcode.com/problems/reformat-date/
4+
* Difficulty: Easy
5+
*
6+
* Given a date string in the form Day Month Year, where:
7+
* - Day is in the set {"1st", "2nd", "3rd", "4th", ..., "30th", "31st"}.
8+
* - Month is in the set {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}.
9+
* - Year is in the range [1900, 2100].
10+
*
11+
* Convert the date string to the format YYYY-MM-DD, where:
12+
* - YYYY denotes the 4 digit year.
13+
* - MM denotes the 2 digit month.
14+
* - DD denotes the 2 digit day.
15+
*/
16+
17+
/**
18+
* @param {string} date
19+
* @return {string}
20+
*/
21+
var reformatDate = function(date) {
22+
const [_, day, month, year] = date.match(/(\d+)\w+\s+(\w+)\s+(\d+)/);
23+
return new Date(`${day} ${month} ${year}`).toISOString().split('T')[0];
24+
};

0 commit comments

Comments
 (0)
Please sign in to comment.