44import java .util .Map ;
55
66class 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