Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions src/week02/haemin/PG_81301.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package week02.haemin;

import java.util.HashMap;
import java.util.*;

// 1
class Solution {

private static HashMap<String, String> 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);
// }
//}