Skip to content

Commit 7cd7d2c

Browse files
committed
[level 1] Title: 숫자 문자열과 영단어, Time: 1.80 ms, Memory: 85.3 MB -BaekjoonHub
1 parent 49e1233 commit 7cd7d2c

File tree

2 files changed

+6
-58
lines changed

2 files changed

+6
-58
lines changed

프로그래머스/1/81301. 숫자 문자열과 영단어/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
### 성능 요약
66

7-
메모리: 75.5 MB, 시간: 13.84 ms
7+
메모리: 85.3 MB, 시간: 1.80 ms
88

99
### 구분
1010

@@ -16,7 +16,7 @@
1616

1717
### 제출 일자
1818

19-
2025년 05월 06일 19:09:12
19+
2025년 05월 06일 20:10:15
2020

2121
### 문제 설명
2222

Lines changed: 4 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,9 @@
1-
import java.util.*;
2-
31
class Solution {
4-
static Map<String, String> map = new HashMap();
5-
62
public int solution(String s) {
7-
8-
String tmp = "";
9-
String result = "";
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(int i=0; i<s.length()-1; i++){
22-
char curr = s.charAt(i);
23-
char next = s.charAt(i+1);
24-
25-
26-
// 현재 인덱스, 다음 인덱스 둘다 문자
27-
if(curr>='a' && curr<='z' && next>='a' && next<='z'){
28-
tmp+=curr;
29-
if(map.containsKey(tmp)){ //문자형태의 숫자들이 연속적으로 나열되어있는 경우 고려
30-
result+=map.get(tmp);
31-
tmp="";
32-
}
33-
}
34-
35-
// 현재 인덱스 문자, 다음 인덱스 숫자
36-
else if(curr>='a' && curr<='z' && next>='0' && next<='9'){
37-
tmp+=curr;
38-
result+=map.get(tmp); //map에서 해당하는 숫자 찾기
39-
tmp=""; //임시 문자열 초기화
40-
}
41-
42-
//현재 인덱스 숫자 -> 결과에 추가
43-
else{
44-
result+=curr;
45-
}
3+
String[] strArr = {"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"};
4+
for(int i = 0; i < strArr.length; i++) {
5+
s = s.replaceAll(strArr[i], Integer.toString(i));
466
}
47-
48-
char c = s.charAt(s.length()-1);
49-
if(c >= 'a' && c <= 'z'){
50-
tmp+=c;
51-
result+=map.get(tmp);
52-
}
53-
else{
54-
result+=c;
55-
}
56-
57-
System.out.println(result);
58-
int answer = Integer.parseInt(result);
59-
return answer;
7+
return Integer.parseInt(s);
608
}
619
}

0 commit comments

Comments
 (0)