Skip to content

Commit 48ce19e

Browse files
committed
[level 2] Title: 오픈채팅방, Time: 156.18 ms, Memory: 166 MB -BaekjoonHub
1 parent ba9c8f0 commit 48ce19e

File tree

2 files changed

+30
-20
lines changed

2 files changed

+30
-20
lines changed

프로그래머스/2/42888. 오픈채팅방/README.md

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

55
### 성능 요약
66

7-
메모리: 182 MB, 시간: 135.35 ms
7+
메모리: 166 MB, 시간: 156.18 ms
88

99
### 구분
1010

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

1717
### 제출 일자
1818

19-
2026년 01월 10일 18:14:41
19+
2026년 02월 06일 14:21:32
2020

2121
### 문제 설명
2222

프로그래머스/2/42888. 오픈채팅방/오픈채팅방.java

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,38 @@
44
import java.util.Map;
55

66
class Solution {
7+
private static final String ENTER = "Enter";
8+
private static final String LEAVE = "Leave";
9+
private static final String CHANGE = "Change";
10+
private static List<String> resultList = new ArrayList<>();
11+
712
public static List<String> solution(String[] record) {
8-
Map<String, String> map = new HashMap<>();
9-
List<String> list = new ArrayList<>();
10-
11-
for (String s : record) {
12-
String[] splitCmd = s.split(" ");
13-
if (splitCmd[0].equals("Enter")) {
14-
map.put(splitCmd[1], splitCmd[2]);
15-
} else if (splitCmd[0].equals("Change")) {
16-
map.replace(splitCmd[1], splitCmd[2]);
13+
Map<String, String> userInfo = new HashMap<>();
14+
15+
for (String command : record) {
16+
String[] splitCommand = command.split(" ");
17+
18+
if (splitCommand[0].equals(ENTER)) {
19+
userInfo.put(splitCommand[1], splitCommand[2]);
20+
}
21+
22+
if (splitCommand[0].equals(CHANGE)) {
23+
userInfo.put(splitCommand[1], splitCommand[2]);
1724
}
1825
}
19-
20-
for (String s : record) {
21-
String[] splitCmd = s.split(" ");
22-
if (splitCmd[0].equals("Enter")) {
23-
list.add(map.get(splitCmd[1]) + "님이 들어왔습니다.");
24-
} else if (splitCmd[0].equals("Leave")) {
25-
list.add(map.get(splitCmd[1]) + "님이 나갔습니다.");
26+
27+
for (String command : record) {
28+
String[] commands = command.split(" ");
29+
30+
if (commands[0].equals(ENTER)) {
31+
resultList.add(userInfo.get(commands[1]) + "님이 들어왔습니다.");
32+
}
33+
34+
if (commands[0].equals(LEAVE)) {
35+
resultList.add(userInfo.get(commands[1]) + "님이 나갔습니다.");
2636
}
2737
}
28-
29-
return list;
38+
39+
return resultList;
3040
}
3141
}

0 commit comments

Comments
 (0)