Skip to content

Commit b6f7753

Browse files
haemin4738Yoepee
andauthored
feat: 2주차 - PG_81301숫자 문자열과 영단어 문제 풀이 [이해민] (#9)
* feat: 2주차 - PG_81301숫자 문자열과 영단어 문제 풀이 [이해민] * Update PG_81301.java * Update PG_81301.java * Update PG_81301.java * Update PG_81301.java * Update PG_81301.java * Update PG_81301.java * Update PG_81301.java --------- Co-authored-by: Dongyeop <110077966+Yoepee@users.noreply.github.com>
1 parent ea34051 commit b6f7753

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

src/week02/haemin/PG_81301.java

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package week02.haemin;
2+
3+
import java.util.HashMap;
4+
import java.util.*;
5+
6+
// 1
7+
class Solution {
8+
9+
private static HashMap<String, String> map = new HashMap<>();
10+
11+
public int solution1(String s) {
12+
// map 구성
13+
map.put("zero", "0");
14+
map.put("one", "1");
15+
map.put("two", "2");
16+
map.put("three", "3");
17+
map.put("four", "4");
18+
map.put("five", "5");
19+
map.put("six", "6");
20+
map.put("seven", "7");
21+
map.put("eight", "8");
22+
map.put("nine", "9");
23+
24+
for(String key : map.keySet()){
25+
s = s.replaceAll(key, map.get(key));
26+
}
27+
28+
int answer = Integer.parseInt(s);
29+
return answer;
30+
}
31+
}
32+
33+
// 2
34+
//class Solution2 {
35+
// public int solution(String s) {
36+
// String[] strArr = {"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"};
37+
// for(int i = 0; i < strArr.length; i++) {
38+
// s = s.replaceAll(strArr[i], Integer.toString(i));
39+
// }
40+
// return Integer.parseInt(s);
41+
// }
42+
//}

0 commit comments

Comments
 (0)