Skip to content

Commit bec9eae

Browse files
add 1507
1 parent d55b388 commit bec9eae

File tree

3 files changed

+85
-0
lines changed

3 files changed

+85
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ _If you like this project, please leave me a star._ ★
88

99
| # | Title | Solutions | Video | Difficulty | Tag
1010
|-----|----------------|---------------|--------|-------------|-------------
11+
|1507|[Reformat Date](https://leetcode.com/problems/reformat-date/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1507.java) | |Easy|String|
1112
|1502|[Can Make Arithmetic Progression From Sequence](https://leetcode.com/problems/can-make-arithmetic-progression-from-sequence/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1502.java) | |Easy|Array, Sort|
1213
|1496|[Path Crossing](https://leetcode.com/problems/path-crossing/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1496.java) | |Easy|String|
1314
|1493|[Longest Subarray of 1's After Deleting One Element](https://leetcode.com/problems/longest-subarray-of-1s-after-deleting-one-element/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1493.java) | |Medium|Array|
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
package com.fishercoder.solutions;
2+
3+
public class _1507 {
4+
public static class Solution1 {
5+
public String reformatDate(String date) {
6+
String[] dates = date.split(" ");
7+
return dates[2] + "-" + getMonth(dates[1]) + "-" + getDay(dates[0]);
8+
}
9+
10+
private String getDay(String day) {
11+
String formatedDay = day.substring(0, day.length() - 2);
12+
if (formatedDay.length() == 1) {
13+
return "0" + formatedDay;
14+
}
15+
return formatedDay;
16+
}
17+
18+
private String getMonth(String month) {
19+
String result = "";
20+
switch (month) {
21+
case "Jan":
22+
result = "01";
23+
break;
24+
case "Feb":
25+
result = "02";
26+
break;
27+
case "Mar":
28+
result = "03";
29+
break;
30+
case "Apr":
31+
result = "04";
32+
break;
33+
case "May":
34+
result = "05";
35+
break;
36+
case "Jun":
37+
result = "06";
38+
break;
39+
case "Jul":
40+
result = "07";
41+
break;
42+
case "Aug":
43+
result = "08";
44+
break;
45+
case "Sep":
46+
result = "09";
47+
break;
48+
case "Oct":
49+
result = "10";
50+
break;
51+
case "Nov":
52+
result = "11";
53+
break;
54+
case "Dec":
55+
result = "12";
56+
break;
57+
}
58+
return result;
59+
}
60+
61+
}
62+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package com.fishercoder;
2+
3+
import com.fishercoder.solutions._1507;
4+
import org.junit.BeforeClass;
5+
import org.junit.Test;
6+
7+
import static junit.framework.TestCase.assertEquals;
8+
9+
public class _1507Test {
10+
private static _1507.Solution1 solution1;
11+
12+
@BeforeClass
13+
public static void setup() {
14+
solution1 = new _1507.Solution1();
15+
}
16+
17+
@Test
18+
public void test1() {
19+
assertEquals("2052-10-20", solution1.reformatDate("20th Oct 2052"));
20+
}
21+
22+
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy