diff --git a/src/week02/haemin/PG_81301.java b/src/week02/haemin/PG_81301.java new file mode 100644 index 0000000..f33696e --- /dev/null +++ b/src/week02/haemin/PG_81301.java @@ -0,0 +1,42 @@ +package week02.haemin; + +import java.util.HashMap; +import java.util.*; + +// 1 +class Solution { + + private static HashMap map = new HashMap<>(); + + public int solution1(String s) { + // map 구성 + map.put("zero", "0"); + map.put("one", "1"); + map.put("two", "2"); + map.put("three", "3"); + map.put("four", "4"); + map.put("five", "5"); + map.put("six", "6"); + map.put("seven", "7"); + map.put("eight", "8"); + map.put("nine", "9"); + + for(String key : map.keySet()){ + s = s.replaceAll(key, map.get(key)); + } + + int answer = Integer.parseInt(s); + return answer; + } +} + +// 2 +//class Solution2 { +// public int solution(String s) { +// String[] strArr = {"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"}; +// for(int i = 0; i < strArr.length; i++) { +// s = s.replaceAll(strArr[i], Integer.toString(i)); +// } +// return Integer.parseInt(s); +// } +//}