문제
내 풀이
class Solution {
public String solution(String[] id_pw, String[][] db) {
String answer = "";
for(int i = 0 ; i < db.length ; i ++){
if(!db[i][0].equals(id_pw[0])){
answer = "fail";
}else{
if(!db[i][1].equals(id_pw[1])){
answer = "wrong pw";
}else{
answer = "login";
}
break;
}
}
return answer;
}
}
다른 사람 풀이 1
import java.util.HashMap;
import java.util.Map;
class Solution {
public String solution(String[] idPw, String[][] db) {
return getDb(db).get(idPw[0]) != null ? getDb(db).get(idPw[0]).equals(idPw[1]) ? "login" : "wrong pw" : "fail";
}
private Map<String, String> getDb(String[][] db) {
Map<String, String> map = new HashMap<>();
for (String[] array : db) {
map.put(array[0], array[1]);
}
return map;
}
}
다른 사람 풀이 2
class Solution {
public String solution(String[] id_pw, String[][] db) {
String answer = "";
for(int i = 0; i < db.length; i++){
if(db[i][0].equals(id_pw[0])){
if(db[i][1].equals(id_pw[1])){
return "login";
}
return "wrong pw";
}
}
return "fail";
}
}