Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitbec9eae

Browse files
add 1507
1 parentd55b388 commitbec9eae

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+
packagecom.fishercoder.solutions;
2+
3+
publicclass_1507 {
4+
publicstaticclassSolution1 {
5+
publicStringreformatDate(Stringdate) {
6+
String[]dates =date.split(" ");
7+
returndates[2] +"-" +getMonth(dates[1]) +"-" +getDay(dates[0]);
8+
}
9+
10+
privateStringgetDay(Stringday) {
11+
StringformatedDay =day.substring(0,day.length() -2);
12+
if (formatedDay.length() ==1) {
13+
return"0" +formatedDay;
14+
}
15+
returnformatedDay;
16+
}
17+
18+
privateStringgetMonth(Stringmonth) {
19+
Stringresult ="";
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+
returnresult;
59+
}
60+
61+
}
62+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
packagecom.fishercoder;
2+
3+
importcom.fishercoder.solutions._1507;
4+
importorg.junit.BeforeClass;
5+
importorg.junit.Test;
6+
7+
importstaticjunit.framework.TestCase.assertEquals;
8+
9+
publicclass_1507Test {
10+
privatestatic_1507.Solution1solution1;
11+
12+
@BeforeClass
13+
publicstaticvoidsetup() {
14+
solution1 =new_1507.Solution1();
15+
}
16+
17+
@Test
18+
publicvoidtest1() {
19+
assertEquals("2052-10-20",solution1.reformatDate("20th Oct 2052"));
20+
}
21+
22+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp