Skip to content

Commit 154d190

Browse files
authored
feat: 2주차 - PG_81301숫자 문자열과 영단어 문제 풀이 [이해민]
1 parent 7797b43 commit 154d190

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

src/week02/haemin/PG_81301.java

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

0 commit comments

Comments
 (0)